sklearn學習筆記

2021-09-27 12:47:00 字數 1397 閱讀 7317

from sklearn.datasets import load_iris

from sklearn.model_selection import train_test_split

from sklearn.feature_extraction import dictvectorizer

from sklearn.feature_extraction.text import countvectorizer

#sklearn 資料呼叫

def dict_demo():

#字典特徵提取

data = [,,]

#1,例項化乙個轉換器

transfer = dictvectorizer(sparse=false)

data_new=transfer.fit_transform(data)

print(「data_new: \n」,data_new)

print(「data_new: \n」, transfer.get_feature_names())

def dictvec():

dict=dictvectorizer(sparse=false)

s = [,,]

data=dict.fit_transform(s)

s = [{}]

name=dict.get_feature_names()

print(name)

print(data)

def count_demo():

#文字特徵提取

#例項化乙個轉換器類

data = ["life is short ,i like python","life is too long ,i dislike python "]

#呼叫fit_transform

transfer = countvectorizer()

datanew = transfer.fit_transform(data)

print("datanew:\n",datanew.toarray())

def count_0demo():

# 漢字文字特徵提取

# 例項化乙個轉換器類

data = ["我 愛 北 京 天 安 門", "我 愛 我 家 "]

# 呼叫fit_transform

transfer = countvectorizer()

datanew = transfer.fit_transform(data)

print("datanew:\n", datanew)

return none

ifname== 『main』:

count_demo()

sklearn學習筆記

1.波士頓房價線性回歸模型 from sklearn import datasets from sklearn.linear model import linearregression boston datasets.load boston data x boston.data y boston.t...

sklearn學習筆記

決策樹一般採用整合,具有隨機,不純度最優 from sklearn import tree from sklearn.datasets import load wine from sklearn.model selection import train test split 用於劃分訓練測試集數目 ...

sk learn 學習筆記八

感知器通常用下面的圖形表示 x1,和是輸入單元。每個輸入單元分別代表乙個特徵。感知器通常用另外乙個輸入單元代表乙個常用誤差項,但是這個輸入單元在圖形中通常被忽略了。中間的圓圈是乙個計算單元,類似神經元的細胞核。連線輸入單元和計算單元的邊類似於樹突。每條邊是乙個權重,或者是乙個引數。引數容易解釋,如果...