FutureWarning: np.matrix usage is deprecated in 1.0 and will raise a TypeError in 1.2

文章提到,使用sklearn的LinearRegression时遇到numpy关于matrix使用的FutureWarning,该警告将在将来的版本中升级为错误。为消除这个警告,可以使用numpy的asarray函数转换矩阵,并通过导入warnings模块设置过滤器忽略此类警告。
FutureWarning: np.matrix usage is deprecated in 1.0 and will raise a TypeError in 1.2. Please convert to a numpy array with np.asarray. For more information see

用sklearn库写了最小二乘,但是python报了上述提示性错误

这是由于sklearn调用了numpy,此错误可以忽略

from sklearn import linear_model
model = linear_model.LinearRegression()
model.fit(X, y)

**用这个来关掉报错**

from warnings import simplefilter
simplefilter(action='ignore', category=FutureWarning)
D:\anaconda\python.exe C:\Users\周程锦\PycharmProjects\pythonProject5\ds\ds.py Attempting to load data from: C:\Users\周程锦\PycharmProjects\pythonProject5\ds\bike.csv Data Info: <class 'pandas.core.frame.DataFrame'> RangeIndex: 17379 entries, 0 to 17378 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 instant 17379 non-null int64 1 dteday 17379 non-null object 2 season 17379 non-null int64 3 yr 17379 non-null int64 4 mnth 17379 non-null int64 5 hr 17379 non-null int64 6 holiday 17379 non-null int64 7 weekday 17379 non-null int64 8 workingday 17379 non-null int64 9 weathersit 17379 non-null int64 10 temp 17379 non-null float64 11 atemp 17379 non-null float64 12 hum 17379 non-null float64 13 windspeed 17379 non-null float64 14 casual 17379 non-null int64 15 registered 17379 non-null int64 16 cnt 17379 non-null int64 dtypes: float64(4), int64(12), object(1) memory usage: 2.3+ MB None Data Description: instant season ... registered cnt count 17379.0000 17379.000000 ... 17379.000000 17379.000000 mean 8690.0000 2.501640 ... 153.786869 189.463088 std 5017.0295 1.106918 ... 151.357286 181.387599 min 1.0000 1.000000 ... 0.000000 1.000000 25% 4345.5000 2.000000 ... 34.000000 40.000000 50% 8690.0000 3.000000 ... 115.000000 142.000000 75% 13034.5000 3.000000 ... 220.000000 281.000000 max 17379.0000 4.000000 ... 886.000000 977.000000 [8 rows x 16 columns] Missing values: instant 0 dteday 0 season 0 yr 0 mnth 0 hr 0 holiday 0 weekday 0 workingday 0 weathersit 0 temp 0 atemp 0 hum 0 windspeed 0 casual 0 registered 0 cnt 0 dtype: int64 C:\Users\周程锦\PycharmProjects\pythonProject5\ds\ds.py:39: FutureWarning: Dropping of nuisance columns in DataFrame reductions (with 'numeric_only=None') is deprecated; in a future version this will raise TypeError. Select only valid columns before calling the reduction. data.fillna(data.mean(), inplace=True) Traceback (most recent call last): File "C:\Users\周程锦\PycharmProjects\pythonProject5\ds\ds.py", line 127, in <module> X_scaled = standardize_features(X) File "C:\Users\周程锦\PycharmProjects\pythonProject5\ds\ds.py", line 50, in standardize_features X_scaled = scaler.fit_transform(X) File "D:\anaconda\lib\site-packages\sklearn\base.py", line 852, in fit_transform return self.fit(X, **fit_params).transform(X) File "D:\anaconda\lib\site-packages\sklearn\preprocessing\_data.py", line 806, in fit return self.partial_fit(X, y, sample_weight) File "D:\anaconda\lib\site-packages\sklearn\preprocessing\_data.py", line 841, in partial_fit X = self._validate_data( File "D:\anaconda\lib\site-packages\sklearn\base.py", line 566, in _validate_data X = check_array(X, **check_params) File "D:\anaconda\lib\site-packages\sklearn\utils\validation.py", line 746, in check_array array = np.asarray(array, order=order, dtype=dtype) File "D:\anaconda\lib\site-packages\pandas\core\generic.py", line 2064, in __array__ return np.asarray(self._values, dtype=dtype) ValueError: could not convert string to float: '2011-01-01' 进程已结束,退出代码为 1
最新发布
06-20
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值