必备!人工智能和数据科学的七大 Python 库( 十 )

接下来我们再次加载生成的 .py文件,你将看到:

1importnumpyasnp

2fromsklearn.model_selectionimporttrain_test_split

3fromsklearn.neighborsimportKNeighborsClassifier

4#NOTE:Make sure that the class is labeled 'class' in the data file

5tpot_data = http://www.veick.cn/news/np.recfromcsv('PATH/TO/DATA/FILE', delimiter='COLUMN_SEPARATOR', dtype=np.float64)

6features = np.delete(tpot_data.view(np.float64).reshape(tpot_data.size,-1), tpot_data.dtype.names.index('class'), axis=1)

7training_features, testing_features, training_classes, testing_classes = \

8train_test_split(features, tpot_data['class'], random_state=42)

9exported_pipeline = KNeighborsClassifier(n_neighbors=4, p=2, weights="distance")

推荐阅读