复制
收藏
提问
全网

import numpy as np import pandas as pd df = pd.read_csv('./wine3.csv') data = df.dropna(axis=1,thresh=df.shape[0]*0.8,inplace=False) data['type'].replace(np.nan,data['type'].mode()[0]) diabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True) diabetes_X = diabetes_X[:, np.newaxis, 2] diabetes_X_train = diabetes_X[:-20] diabetes_X_test = diabetes_X[-20:] diabetes_y_train = diabetes_y[:-20] diabetes_y_test = diabetes_y[-20:] regr = linear_model.LinearRegression() regr.fit(diabetes_X_train, diabetes_y_train) diabetes_y_pred = regr.predict(diabetes_X_test) print("Coefficients: \n", regr.coef_) print("Mean squared error: %.2f" % mean_squared_error(diabetes_y_test, diabetes_y_pred)) plt.scatter(diabetes_X_test, diabetes_y_test, color="black") plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3) plt.xticks(()) plt.yticks(()) 1.plt.show()

f0e0959ef
4个月前
全网
文档
学术
百科
知识库
时间不限
自动

理解问题import numpy as np import pandas as pd df = pd.read_csv('./wine3.csv') data = df.dropna(axis=1,thresh=df.shape[0]*0.8,inplace=False) data['type'].replace(np.nan,data['type'].mode()[0]) diabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True) diabetes_X = diabetes_X[:, np.newaxis, 2] diabetes_X_train = diabetes_X[:-20] diabetes_X_test = diabetes_X[-20:] diabetes_y_train = diabetes_y[:-20] diabetes_y_test = diabetes_y[-20:] regr = linear_model.LinearRegression() regr.fit(diabetes_X_train, diabetes_y_train) diabetes_y_pred = regr.predict(diabetes_X_test) print("Coefficients: \n", regr.coef_) print("Mean squared error: %.2f" % mean_squared_error(diabetes_y_test, diabetes_y_pred)) plt.scatter(diabetes_X_test, diabetes_y_test, color="black") plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3) plt.xticks(()) plt.yticks(()) 1.plt.show()

已完成理解import numpy as np import pandas as pd df = pd.read_csv('./wine3.csv') data = df.dropna(axis=1,thresh=df.shape[0]*0.8,inplace=False) data['type'].replace(np.nan,data['type'].mode()[0]) diabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True) diabetes_X = diabetes_X[:, np.newaxis, 2] diabetes_X_train = diabetes_X[:-20] diabetes_X_test = diabetes_X[-20:] diabetes_y_train = diabetes_y[:-20] diabetes_y_test = diabetes_y[-20:] regr = linear_model.LinearRegression() regr.fit(diabetes_X_train, diabetes_y_train) diabetes_y_pred = regr.predict(diabetes_X_test) print("Coefficients: \n", regr.coef_) print("Mean squared error: %.2f" % mean_squared_error(diabetes_y_test, diabetes_y_pred)) plt.scatter(diabetes_X_test, diabetes_y_test, color="black") plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3) plt.xticks(()) plt.yticks(()) 1.plt.show()

展开阅读网页

更专业一些
转笔记
专业
import numpy as np import pandas as pd df = pd.read_csv('./wine3.csv') data = df.dropna(axis=1,thresh=df.shape[0]*0.8,inplace=False) data['type'].replace(np.nan,data['type'].mode()[0]) diabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True) diabetes_X = diabetes_X[:, np.newaxis, 2] diabetes_X_train = diabetes_X[:-20] diabetes_X_test = diabetes_X[-20:] diabetes_y_train = diabetes_y[:-20] diabetes_y_test = diabetes_y[-20:] regr = linear_model.LinearRegression() regr.fit(diabetes_X_train, diabetes_y_train) diabetes_y_pred = regr.predict(diabetes_X_test) print("Coefficients: \n", regr.coef_) print("Mean squared error: %.2f" % mean_squared_error(diabetes_y_test, diabetes_y_pred)) plt.scatter(diabetes_X_test, diabetes_y_test, color="black") plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3) plt.xticks(()) plt.yticks(()) 1.plt.show()
不在提醒

更专业内容正在努力生成中
知识树
import numpy as np import pandas as pd df = pd.read_csv('./wine3.csv') data = df.dropna(axis=1,thresh=df.shape[0]*0.8,inplace=False) data['type'].replace(np.nan,data['type'].mode()[0]) diabetes_X, diabetes_y = datasets.load_diabetes(return_X_y=True) diabetes_X = diabetes_X[:, np.newaxis, 2] diabetes_X_train = diabetes_X[:-20] diabetes_X_test = diabetes_X[-20:] diabetes_y_train = diabetes_y[:-20] diabetes_y_test = diabetes_y[-20:] regr = linear_model.LinearRegression() regr.fit(diabetes_X_train, diabetes_y_train) diabetes_y_pred = regr.predict(diabetes_X_test) print("Coefficients: \n", regr.coef_) print("Mean squared error: %.2f" % mean_squared_error(diabetes_y_test, diabetes_y_pred)) plt.scatter(diabetes_X_test, diabetes_y_test, color="black") plt.plot(diabetes_X_test, diabetes_y_pred, color="blue", linewidth=3) plt.xticks(()) plt.yticks(()) 1.plt.show()
如何使用pandas处理缺失数据?
如何使用线性回归模型进行预测?
sklearn中mean_squared_error函数如何使用?

以上内容由AI搜集生成,仅供参考

在线客服