标签:依据 有监督 课程 决策树 bsp series port get 获取
1 import pandas 2 3 data=pandas.read_csv( 4 "C:\\Users\\Jw\\Desktop\\python_work\\Python数据挖掘实战课程课件\\5.3\\data.csv") 5 6 dummyColumns=["Gender", "ParentEncouragement"] 7 8 for column in dummyColumns: 9 data[column]=data[column].astype("category") 10 11 12 dummiesData=pandas.get_dummies( 13 data, 14 columns=dummyColumns, 15 prefix=dummyColumns, 16 prefix_sep="=", 17 drop_first=True) 18 19 dummiesData.columns
fData=dummiesData[[ ‘ParentIncome‘, ‘IQ‘, ‘Gender=Male‘, ‘ParentEncouragement=Not Encouraged‘]] tData=dummiesData["CollegePlans"]
我注意到:fData即是特征数据为一个DataFrame数据框,而tData则是一个Series
1 from sklearn.tree import DecisionTreeClassifier 2 3 dtModel=DecisionTreeClassifier(max_leaf_nodes=8) #该处为调优 4 5 from sklearn.model_selection import cross_val_score 6 7 cross_val_score( 8 dtModel, 9 fData,tData,cv=10)
标签:依据 有监督 课程 决策树 bsp series port get 获取
原文地址:https://www.cnblogs.com/U940634/p/9746295.html