文章预览
交叉验证是数据科学家必不可少的技术,但很容易被误用。 图解机器学习中的 12 种交叉验证技术 我们在在构建机器学习模型时,特别注意需要避免的错误,今天我们一起看看~ 交叉验证的意义是什么? 机器学习的基本思想是:在“训练”数据集上拟合模型,并在单独的“测试”数据上评估其性能(该数据应该模拟模型在现实世界中的表现): from sklearn.model_selection import train_test_split from sklearn.linear_model import LogisticRegression from sklearn.metrics import roc_auc_score from sklearn.datasets import make_classification # 示例数据集 X, y = make_classification(n_samples= 1000 , n_features= 20 , random_state= 42 ) X_train, X_test, y_train, y_test = train_test_split(X, y, test_size= 0.2 ) clf = LogisticRegression() clf.fit(X_train, y_train) y_pred = clf.predict(X_test) rocauc = roc_auc_sc
………………………………