0
# Load the data
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import sklearn

oecd = pd.read_csv("oecd.csv", thousands=',')
gd_per_capita = pd.read_csv("gdp_per_capita.csv", thousands=',',delimiter='\t', encoding='latin1', na_values="n/a")

#Prepare the data

country_stats = prepare_country_stats(oecd, gdp_per_capita)
x = np.c_[country_stats["GDP per capita"]]
y = np.c[country_stats["Life satisfaction"]]

#Visualise the data

country_stats.plot(kind='scatter', x="GDP per capita", y='Life satisfaction')
plt.show()

# Select a linear model
model = sklearn.linear_model.LinearRegression()

# Train the code
model.fit(x,y)

# Make a prediction for Cyprus
x_new = [[22587]] # Cyprus GDP per capita
print(model.predict(x_new))

Whenever I try to run this code in Python 3.4.4 this throws up:

Traceback (most recent call last):
  File "C:\Users\Ranjan.Ranjan-PC\Desktop\Hands-On\gdp.py", line 6, in <module>
    import sklearn
  File "C:\Python34\lib\site-packages\sklearn\__init__.py", line 134, in <module>
    from .base import clone
  File "C:\Python34\lib\site-packages\sklearn\base.py", line 10, in <module>
    from scipy import sparse
  File "C:\Python34\lib\site-packages\scipy\sparse\__init__.py", line 213, in <module>
    from .csr import *
  File "C:\Python34\lib\site-packages\scipy\sparse\csr.py", line 13, in <module>
    from ._sparsetools import csr_tocsc, csr_tobsr, csr_count_blocks, \
ImportError: DLL load failed: %1 is not a valid Win32 application.

sklearn has been installed though

What is wrong?

illright
  • 3,991
  • 2
  • 29
  • 54
ranjan
  • 53
  • 1
  • 9
  • How did you install sklearn? – L Selter Aug 30 '17 at 07:55
  • Make sure you are using the matching versions of libraries to your system, ie. if your OS is 64-bit, then use 64-bit python and 64-bit versions of libraries. If 64-bit version of libraries is not found, then use 32-bit python only. See here for `matplotlib` :- https://stackoverflow.com/a/26640324/3374996 – Vivek Kumar Aug 30 '17 at 09:35

0 Answers0