import pandas as pd
from sklearn.preprocessing import OneHotEncoder
from sklearn.preprocessing import PolynomialFeatures
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.linear_model import Ridge
path = "hour.csv"
data = pd.read_csv(path,na_values='?')## 删除无用的列
data.drop(["casual","registered","dteday"],axis=1,inplace=True)
data.head()
## 检查哪些特征需要做独热编码
# seasson mnth hr holiday weekday
data_trans = data[["season","mnth","hr","weekday"]]
## 独热编码,对需要进行独热编码的列编码
hotCoder = OneHotEncoder(sparse=False,handle_unknown='ignore')
hot=hotCoder.fit_transform(data_trans)
data_trans_hot = pd.DataFrame(hot)
# print(data.head)
# 删除掉独热编码的列
data.drop(["season","mnth","hr","weekday"],axis
LinearRegression 预测
最新推荐文章于 2024-06-24 07:50:22 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)