Kaggle_machinelearning Level 1记录

机器学习初探

不要迷信算法岗和现在炒热的AI,算法工程师首先得是一个工程师,热情的吸收技术,多思考,眼界决定一切,时间不会骗人。

  • Kaggle Learn Level 1
  • Kaggle Learn Level 2
  • Machine Learning in a Week 项目 学习scikitlearn 敲一个实际简单的项目
  • 经典的方法论文,如卷积神经网络,反向传播,梯度下降
  • 统计学习方法 算法推导
  • 数据挖掘课跟上进度

# Code you have previously used to load data
import pandas as pd
from sklearn.metrics import mean_absolute_error
from sklearn.model_selection import train_test_split
from sklearn.tree import DecisionTreeRegressor


# Path of the file to read
iowa_file_path = '../input/home-data-for-ml-course/train.csv'

home_data = pd.read_csv(iowa_file_path)
# Create target object and call it y
y = home_data.SalePrice
# Create X
features = ['LotArea', 'YearBuilt', '1stFlrSF', '2ndFlrSF', 'FullBath', 'BedroomAbvGr', 'TotRmsAbvGrd']
X = home_data[features]

# Split into validation and training data
train_X, val_X, train_y, val_y = train_test_split(X, y, random_state=1)

# Specify Model
iowa_model = DecisionTreeRegressor(random_state=1)
# Fit Model
iowa_model.fit(train_X, train_y)

# Make validation predictions and calculate mean absolute error
val_predictions = iowa_model.predict(val_X)
val_mae = mean_absolute_error(val_predictions, val_y)
print("Validation MAE when not specifying max_leaf_nodes: {:,.0f}".format(val_mae))

# Using best value for max_leaf_nodes
iowa_model = DecisionTreeRegressor(max_leaf_nodes=100, random_state=1)
iowa_model.fit(train_X, train_y)
val_predictions = iowa_model.predict(val_X)
val_mae = mean_absolute_error(val_predictions, val_y)
print("Validation MAE for best value of max_leaf_nodes: {:,.0f}".format(val_mae))
###Use RandomForestRegressor
#from sklearn.ensemble import RandomForestRegressor
# Define the model. Set random_state to 1
#rf_model = RandomForestRegressor(random_state=1)

# fit your model
#rf_model.fit(train_X, train_y)

# Calculate the mean absolute error of your Random Forest model on the validation data
#rf_val_mae = mean_absolute_error(val_y, rf_model.predict(val_X))
#print("Validation MAE for Random Forest Model: {}".format(rf_val_mae))

决策树模型
随机森林模型
过拟合
模型 策略 算法
训练数据集合->确定假设空间->确定学习的策略->实现求解最优模型的算法->通过学习方法选择最优模型->利用模型对新数据预测或分析

猜你喜欢

转载自blog.csdn.net/u013453787/article/details/83059195