# 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))
每当我尝试在Python 3.4.4中运行此代码时,都会抛出:
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
已安装
有什么问题?