多项式回归图上的多重迹

2024-03-28 13:12:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在实现一个简单的多项式回归来预测给定大小的视频的时间,这是我自己的数据集。现在不知为什么,我的情节有多处痕迹。在

# Importing the libraries
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd

# Importing the dataset
dataset = pd.read_csv('estSize.csv')
X = dataset.iloc[:, 0].values.reshape(-1,1)
y = dataset.iloc[:, 1].values.reshape(-1,1)

from sklearn.linear_model import LinearRegression

# Fitting Polynomial Regression to the dataset
from sklearn.preprocessing import PolynomialFeatures
poly_reg = PolynomialFeatures(degree = 2)
X_poly = poly_reg.fit_transform(X)
poly_reg.fit(X_poly, y)
lin_reg_2 = LinearRegression()
lin_reg_2.fit(X_poly, y)

# Visualising the Polynomial Regression results
plt.scatter(X, y, color = 'red')
plt.plot(X, lin_reg_2.predict(poly_reg.fit_transform(X)), color = 'blue')
plt.show()

This is my output


Tags: csvtheimportaspltregdatasetfit
1条回答
网友
1楼 · 发布于 2024-03-28 13:12:46

您的数据需要根据预测值排序。在

排队之后

dataset = pd.read_csv('estSize.csv')

添加此行:

^{pr2}$

其中,col1是文件大小值的列标题。在

相关问题 更多 >