【发布时间】:2017-04-17 21:57:52
【问题描述】:
我正在尝试制作线性回归模型,根据父亲的长度预测儿子的长度
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
import seaborn as sns
%matplotlib inline
from sklearn.linear_model import LinearRegression
Headings_cols = ['Father', 'Son']
df = pd.read_csv('http://www.math.uah.edu/stat/data/Pearson.txt',
delim_whitespace=True, names=Headings_cols)
X = df['Father']
y = df['Son']
model2 = LinearRegression()
model2.fit(y, X)
plt.scatter(X, y,color='g')
plt.plot(X, model.predict(X),color='g')
plt.scatter(y, X, color='r')
plt.plot(y, X, color='r')
我得到错误
ValueError: could not convert string to float: 'Father'
第二件事是计算儿子的平均长度,以及均值的标准误?
【问题讨论】:
-
你在哪一行代码中得到了那个错误?
-
X = df['父亲'] y = df['儿子']
标签: numpy matplotlib scikit-learn curve-fitting