<jupyter_start><jupyter_text>Decision Tree  ref: http://scikit-learn.org/stable/modules/generated/sklearn.tree.DecisionTreeClassifier.html<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score
from sklearn.datasets import load_breast_cancer
from sklearn.tree import DecisionTreeClassifier


# Load data
cancer = load_breast_cancer()
print(cancer.feature_names)
print(cancer.target_names)
x = cancer.data 
y = cancer.target

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2, random_state=1)

model = DecisionTreeClassifier(min_samples_leaf=3)
model.fit(x_train, y_train)

y_pred = model.predict(x_test)


accuracy = accuracy_score(y_test, y_pred)
num_correct_samples = accuracy_score(y_test, y_pred, normalize=False)


print(f'number of correct sample: {num_correct_samples}')
print(f'accuracy: {accuracy}')<jupyter_output>['mean radius' 'mean texture' 'mean perimeter' 'mean area'
 'mean smoothness' 'mean compactness' 'mean concavity'
 'mean concave points' 'mean symmetry' 'mean fractal dimension'
 'radius error' 'texture error' 'perimeter error' 'area error'
 'smoothness error' 'compactness error' 'concavity error'
 'concave points error' 'symmetry error' 'fractal dimension error'
 'worst radius' 'worst texture' 'worst perimeter' 'worst area'
 'worst smoothness' 'worst compactness' 'worst concavity'
 'worst concave points' 'worst symmetry' 'worst fractal dimension']
['malignant' 'benign']
number of correct sample: 109
accuracy: 0.956140350877193<jupyter_text>Random Forest  ref: http://scikit-learn.org/stable/modules/generated/sklearn.ensemble.RandomForestClassifier.html<jupyter_code>from sklearn.ensemble import RandomForestClassifier

# Load data
cancer = load_breast_cancer()
x = cancer.data 
y = cancer.target

x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)


model = RandomForestClassifier(max_depth=6, n_estimators=10)
model.fit(x_train, y_train)

y_pred = model.predict(x_test)


accuracy = accuracy_score(y_test, y_pred)
num_correct_samples = accuracy_score(y_test, y_pred, normalize=False)

print('number of correct sample: {}'.format(num_correct_samples))
print('accuracy: {}'.format(accuracy))<jupyter_output>number of correct sample: 112
accuracy: 0.9824561403508771
{'fraction_non_alphanumeric': 0.10396250532594802, 'fraction_numerical': 0.020451640391989774, 'mean_word_length': 7.446043165467626, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '906', 'license': 'MIT', 'n_tokens_mistral': 849, 'n_tokens_neox': 803, 'n_words': 187, 'path': 'mod09.ipynb', 'repo_name': 'theabc50111/machine_learning_tibame', 'size': '2347'}