生活随笔
收集整理的這篇文章主要介紹了
Boston波士顿房价数据下载
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
下載地址:https://archive.ics.uci.edu/ml/machine-learning-databases/housing/housing.data
打開方式: 直接用excel可以打開,轉存為csv等
模型訓練
from sklearn
.linear_model
import Lasso
from sklearn
.preprocessing
import StandardScaler
from sklearn
.datasets
import load_bostonboston
= load_boston
()
scaler
= StandardScaler
()X
= scaler
.fit_transform
(boston
["data"])
print('X',X
)
Y
= boston
["target"]
print('Y', Y
)
names
= boston
["feature_names"]
print('names',names
)
LASSO懲罰回歸
from sklearn
.linear_model
import Lasso
from sklearn
.preprocessing
import StandardScaler
from sklearn
.datasets
import load_boston
import numpy
as np
def pretty_print_linear(coefs
, names
= None, sort
= False):if names
is None:names
= ["X%s" % x
for x
in range(len(coefs
))]lst
= zip(coefs
, names
)if sort
:lst
= sorted(lst
, key
= lambda x
:-np
.abs(x
[0]))return " + ".join
("%s * %s" % (np
.round(coef
, 3), name
) for coef
, name
in lst
)
boston
= load_boston
()
scaler
= StandardScaler
()
X
= scaler
.fit_transform
(boston
["data"])
Y
= boston
["target"]
names
= boston
["feature_names"]lasso
= Lasso
(alpha
=.3)
lasso
.fit
(X
, Y
)print("lasso model:", pretty_print_linear
(lasso
.coef_
, names
, sort
= True))
總結
以上是生活随笔為你收集整理的Boston波士顿房价数据下载的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。