<jupyter_start><jupyter_text><jupyter_code>#import funtion
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

#import data
from google.colab import files
uploaded = files.upload()

see_data = pd.read_csv('heart.csv') # Read in csv file to dataframe in Pandas
see_data.head()

#split data into  train and test
X = see_data.iloc[:, 0: 12]
X
y = see_data.iloc[:, [13]]
y
#model training
#split data
from sklearn.model_selection import train_test_split
X_train,X_test,y_train,y_test=train_test_split(X,y,test_size=.2,random_state=0)
#这里的random_state就是为了保证程序每次运行都分割一样的训练集和测试集。
#否则，同样的算法模型在不同的训练集和测试集上的效果不一样。


X_train
y_train
#import to model
from sklearn.ensemble import RandomForestClassifier
np.random.seed(1)
model=RandomForestClassifier()

model.fit(X_train,y_train) #use train data training

model.score(X_test,y_test)#
#模型预测 (Predict)
y_pred = model.predict(X_test)#
#性能指标 (Performance Matrics)

from sklearn.metrics import confusion_matrix, accuracy_score, classification_report
# Confusion matrix for the random forest classification
print(confusion_matrix(y_test, y_pred))
# Accuracy score
print(accuracy_score(y_test, y_pred))
# classification report
print(classification_report(y_test, y_pred))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0926517571884984, 'fraction_numerical': 0.006389776357827476, 'mean_word_length': 7.886524822695035, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '456394', 'license': 'MIT', 'n_tokens_mistral': 493, 'n_tokens_neox': 500, 'n_words': 106, 'path': 'assignment2.ipynb', 'repo_name': 'Louie-in-yr-AREA/HiTechOnlineCourse', 'size': '1252'}