import autosklearn.classification
import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics
if __name__ == "__main__":
print('loading data...')
X, y = sklearn.datasets.load_digits(return_X_y=True)
print('finish loading.')
X_train, X_test, y_train, y_test = \
sklearn.model_selection.train_test_split(X, y, random_state=1)
automl = autosklearn.classification.AutoSklearnClassifier(time_left_for_this_task=60,per_run_time_limit=10,n_jobs=2)
print('training ...')
automl.fit(X_train, y_train)
y_hat = automl.predict(X_test)
print("Accuracy score", sklearn.metrics.accuracy_score(y_test, y_hat))
import autosklearn.regression
import sklearn.model_selection
import sklearn.datasets
import sklearn.metrics
# 加载一个回归数据集,例如波士顿房价数据集
X, y = sklearn.datasets.load_boston(return_X_y=True)
# 划分训练集和测试集
X_train, X_test, y_train, y_test = sklearn.model_selection.train_test_split(X, y, random_state=1)
# 初始化AutoSklearnRegressor
automl = autosklearn.regression.AutoSklearnRegressor(
time_left_for_this_task=120, # 设置模型训练时间(秒)
per_run_time_limit=30 # 设置每个模型训练时间的限制(秒)
)
# 训练模型
automl.fit(X_train, y_train)
# 预测测试集
y_pred = automl.predict(X_test)
# 评估模型
print("R2 score:", sklearn.metrics.r2_score(y_test, y_pred))
print("Mean squared error:", sklearn.metrics.mean_squared_error(y_test, y_pred))
# 查看找到的最佳模型
print(automl.show_models())