国产片侵犯亲女视频播放_亚洲精品二区_在线免费国产视频_欧美精品一区二区三区在线_少妇久久久_在线观看av不卡

腳本之家,腳本語言編程技術(shù)及教程分享平臺(tái)!
分類導(dǎo)航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|

服務(wù)器之家 - 腳本之家 - Python - python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

2022-03-06 00:37Python學(xué)習(xí)與數(shù)據(jù)挖掘 Python

這篇文章主要為大家介紹了python人工智能human learn繪圖就可以創(chuàng)建機(jī)器學(xué)習(xí)模型的示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助

如今,數(shù)據(jù)科學(xué)家經(jīng)常給帶有標(biāo)簽的機(jī)器學(xué)習(xí)模型數(shù)據(jù),以便它可以找出規(guī)則。

這些規(guī)則可用于預(yù)測新數(shù)據(jù)的標(biāo)簽。

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

這很方便,但是在此過程中可能會(huì)丟失一些信息。也很難知道引擎蓋下發(fā)生了什么,以及為什么機(jī)器學(xué)習(xí)模型會(huì)產(chǎn)生特定的預(yù)測。

除了讓機(jī)器學(xué)習(xí)模型弄清楚所有內(nèi)容之外,還有沒有一種方法可以利用我們的領(lǐng)域知識(shí)來設(shè)置數(shù)據(jù)標(biāo)記的規(guī)則?

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

是的,這可以通過 human-learn 來完成。

 

什么是 human-learn

human-learn 是一種工具,可讓你使用交互式工程圖和自定義模型來設(shè)置數(shù)據(jù)標(biāo)記規(guī)則。在本文中,我們將探索如何使用 human-learn 來創(chuàng)建帶有交互式圖紙的模型。

安裝 human-learn

pip install human-learn

我將使用來自sklearn的Iris數(shù)據(jù)來展示human-learn的工作原理。

from sklearn.datasets import load_iris
from sklearn.model_selection import train_test_split
import pandas as pd 
# Load data
X, y = load_iris(return_X_y=True, as_frame=True)
X.columns = ['sepal_length', 'sepal_width', 'petal_length', 'petal_width']
# Train test split
X_train, X_test, y_train, y_test = train_test_split(X, y, random_state=1)
# Concatenate features and labels of the training data
train = pd.concat([X_train, pd.DataFrame(y_train)], axis=1)
train

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

 

互動(dòng)繪圖

human-learn 允許你繪制數(shù)據(jù)集,然后使用工程圖將其轉(zhuǎn)換為模型。 為了演示這是如何有用的,想象一下如何創(chuàng)建數(shù)據(jù)集的散點(diǎn)圖,如下所示:

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

查看上面的圖時(shí),你會(huì)看到如何將它們分成3個(gè)不同的區(qū)域,如下所示:

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

但是,可能很難將圖形編寫為規(guī)則并將其放入函數(shù)中,human-learn的交互式繪圖將派上用場。

from hulearn.experimental.interactive import InteractiveCharts
charts = InteractiveCharts(train, labels='target')
charts.add_chart(x='sepal_length', y='sepal_width')

– 動(dòng)圖01

繪制方法:使用雙擊開始繪制多邊形。然后單擊以創(chuàng)建多邊形的邊。再次雙擊可停止繪制當(dāng)前多邊形。

我們對其他列也做同樣的事情:

charts.add_chart(x='petal_length', y='petal_width')

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

 

創(chuàng)建模型并進(jìn)行預(yù)測

一旦完成對數(shù)據(jù)集的繪制,就可以使用以下方法創(chuàng)建模型:

from hulearn.classification import InteractiveClassifier
model = InteractiveClassifier(json_desc=charts.data())
preds = model.fit(X_train, y_train).predict_proba(X_train)
print(preds.shape) # Output: (150, 3)

cool! 我們將工程圖輸入InteractiveClassifier類,使用類似的方法來擬合sklearn的模型,例如fit和predict_proba。

讓我們來看看pred的前5行:

print('Classes:', model.classes_)
print('Predictions:\n', preds[:5, :])
"""Output
Classes: [1, 2, 0]
Predictions:
[[5.71326574e-01 4.28530630e-01 1.42795945e-04]
[2.00079952e-01 7.99720168e-01 1.99880072e-04]
[2.00079952e-01 7.99720168e-01 1.99880072e-04]
[2.49812641e-04 2.49812641e-04 9.99500375e-01]
[4.99916708e-01 4.99916708e-01 1.66583375e-04]]
"""

需要說明的是,predict_proba給出了樣本具有特定標(biāo)簽的概率。 例如,[5.71326574e-01 4.28530630e-01 1.42795945e-04]的第一個(gè)預(yù)測表示樣本具有標(biāo)簽1的可能性為57.13%,樣本具有標(biāo)簽2的可能性為42.85%,而樣本為標(biāo)簽2的可能性為0.014% 該樣本的標(biāo)簽為0。

 

預(yù)測新數(shù)據(jù)

# Get the first sample of X_test
new_sample = new_sample = X_test.iloc[:1]
# Predict
pred = model.predict(new_sample)
real = y_test[:1]
print("The prediction is", pred[0])
print("The real label is", real.iloc[0])

 

解釋結(jié)果

為了了解模型如何根據(jù)該預(yù)測進(jìn)行預(yù)測,讓我們可視化新樣本。

def plot_prediction(prediction: int, columns: list):
  """Plot new sample
  Parameters
  ----------
  prediction : int
      prediction of the new sample
  columns : list
      Features to create a scatter plot 
  """    
  index = prediction_to_index[prediction] 
  col1, col2 = columns    
  plt.figure(figsize=(12, 3))
  plt.scatter(X_train[col1], X_train[col2], c=preds[:, index])
  plt.plot(new_sample[col1], new_sample[col2], 'ro', c='red', label='new_sample')    
  plt.xlabel(col1)
  plt.ylabel(col2)
  plt.title(f"Label {model.classes_[index]}")
  plt.colorbar()
  plt.legend()

使用上面的函數(shù)在petal_length和petal_width繪圖上繪制一個(gè)新樣本,該樣本的點(diǎn)被標(biāo)記為0的概率著色。

plot_prediction(0, columns=['petal_length', 'petal_width'])

python人工智能human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型

其他列也是如此,我們可以看到紅點(diǎn)位于具有許多黃點(diǎn)的區(qū)域中! 這就解釋了為什么模型預(yù)測新樣本的標(biāo)簽為0。這很酷,不是嗎?

 

預(yù)測和評估測試數(shù)據(jù)

現(xiàn)在,讓我們使用該模型來預(yù)測測試數(shù)據(jù)中的所有樣本并評估其性能。 開始使用混淆矩陣進(jìn)行評估:

from sklearn.metrics import confusion_matrix, f1_score
predictions = model.predict(X_test)
confusion_matrix(y_test, predictions, labels=[0,1,2])
array([[13,  0,  0],
     [ 0, 15,  1],
     [ 0,  0,  9]])

我們還可以使用F1分?jǐn)?shù)評估結(jié)果:

f1_score(y_test, predictions, average='micro')

 

結(jié)論

剛剛我們學(xué)習(xí)了如何通過繪制數(shù)據(jù)集來生成規(guī)則來標(biāo)記數(shù)據(jù)。 這并不是說你應(yīng)該完全消除機(jī)器學(xué)習(xí)模型,而是在處理數(shù)據(jù)時(shí)加入某種人工監(jiān)督。

以上就是python人工智能human learn繪圖可創(chuàng)建機(jī)器學(xué)習(xí)模型的詳細(xì)內(nèi)容,更多關(guān)于human learn繪圖創(chuàng)建機(jī)器學(xué)習(xí)模型的資料請關(guān)注服務(wù)器之家其它相關(guān)文章!

原文鏈接:https://blog.csdn.net/weixin_38037405/article/details/117856231

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 日韩一区欧美 | 国产精品视频一区二区三区不卡 | 最近韩国日本免费高清观看 | 久久视频免费看 | 国产精彩视频 | 91最新 | 午夜男人天堂 | 黄色av影视 | 亚洲国产精品一区久久av篠田 | 亚洲精品乱码久久久久久蜜糖图片 | 日韩电影免费观看 | 欧美成人精品一区二区三区 | 国产成人精品亚洲日本在线观看 | 久操视频免费在线观看 | 成人a视频在线观看 | 国产一区二区三区免费观看 | 999久久久国产999久久久 | 国产经典一区 | 欧美福利视频 | 久久久蜜臀 | www.久草 | 日韩免费av一区二区 | 亚洲欧美另类图片 | 九九精品视频在线观看 | 国产综合久久 | 国产精品视频网 | 国产亚洲欧美在线 | 国产亚洲一区二区精品 | 北条麻妃99精品青青久久主播 | 欧美淫视频 | 日韩欧美一区二区三区 | 欧洲成人在线 | 91精品国产乱码久久久久久 | 91精品国产91久久久 | 久久久久亚洲 | 国产免费av在线 | 亚洲欧美日韩在线 | 九九资源站 | 精品一二区 | 中文字幕在线观看第一页 | 久久久青草婷婷精品综合日韩 |