Scikit-learn 模型構建入門:Python 機器學習庫
本文介紹了在 Python 機器學習庫 Scikit-learn 中進行模型構建。
這是一個免費的機器學習庫。它支援多種演算法,例如隨機森林、向量機和 k 近鄰,並可直接使用 Numpy 和 Scipy 實現。
匯入資料集
import pandas Url = < specify your URL here> data=pandas.rad_csv(url)
資料探索和清洗
可以使用 head 方法根據需要指定/篩選記錄。
data.head() data.head(n=4) # restricting the record to be 4
我們還可以實現資料集的最後幾條記錄
data.tail() data.tail(n=4) # restricting the record to be 4
現在進入資料視覺化階段
為此,我們使用 Seaborn 模組和 matplotlib 來視覺化資料
import seaborn as s import matplotlib.pyplot as plt sns.set(style="whitegrid", color_codes=True) # create a countplot sns.countplot('Route To Market',data=sales_data,hue = 'Opportunity Result')
預處理資料
from sklearn import preprocessing le = preprocessing.LabelEncoder() #convert the columns into numeric values encoded_value = le.fit_transform(list of column names) print(encoded_value)
最終,我們透過訓練資料集達到模型構建階段。
結論
本文介紹瞭如何在 Scikit-learn(一個適用於 Python 的庫)中構建模型。
廣告