<jupyter_start><jupyter_text>To perform classification analysis on Iris dataset. Perform any two classification algorithms and compare the accuracy.  Importing modules with a shorcut<jupyter_code>import numpy as np
import pandas as pd
import matplotlib.pyplot as plt<jupyter_output><empty_output><jupyter_text>load data frame<jupyter_code>df = pd.read_csv("D:\\Apps & files\\Codes\\python-from-scrach\\AI_and_ml\\basic\\iris.csv")<jupyter_output><empty_output><jupyter_text>Define data and model<jupyter_code>X=df.iloc[:,1:5]
y=df.iloc[:,5]<jupyter_output><empty_output><jupyter_text>Split data into training and test datasets (training will be based on 70% of data)<jupyter_code>from sklearn.model_selection import train_test_split

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.3, random_state=0)<jupyter_output><empty_output><jupyter_text>test_size: if integer, number of examples into test dataset; if between 0.0 and 1.0, means proportion<jupyter_code>print('There are {} samples in the training set and {} samples in the test set'.format(X_train.shape[0], X_test.shape[0]))
from sklearn.preprocessing import StandardScaler
from sklearn.model_selection import cross_val_score

sc = StandardScaler()
sc.fit(X_train)
X_train_std = sc.transform(X_train)
X_test_std = sc.transform(X_test)<jupyter_output><empty_output><jupyter_text>XGBOOST<jupyter_code>import xgboost as xgb

xgb_clf = xgb.XGBClassifier()
xgb_clf = xgb_clf.fit(X_train_std, y_train)

print('The accuracy of the XGBoost classifier on training data is {:.2f}'.format(xgb_clf.score(X_train_std, y_train)))
print('The accuracy of the XGBoost classifier on test data is {:.2f}'.format(xgb_clf.score(X_test_std, y_test)))<jupyter_output>C:\Users\hello\AppData\Local\Programs\Python\Python39\lib\site-packages\xgboost\sklearn.py:1146: UserWarning: The use of label encoder in XGBClassifier is deprecated and will be removed in a future release. To remove this warning, do the following: 1) Pass option use_label_encoder=False when constructing XGBClassifier object; and 2) Encode your labels (y) as integers starting with 0, i.e. 0, 1, 2, ..., [num_class - 1].
  warnings.warn(label_encoder_deprecation_msg, UserWarning)<jupyter_text>Decision tree regression<jupyter_code>from sklearn import tree

#Create tree object
decision_tree = tree.DecisionTreeClassifier(criterion='gini')

#Train DT based on scaled training set
decision_tree.fit(X_train_std, y_train)

#Print performance
print('The accuracy of the Decision Tree classifier on training data is {:.2f}'.format(decision_tree.score(X_train_std, y_train)))
print('The accuracy of the Decision Tree classifier on test data is {:.2f}'.format(decision_tree.score(X_test_std, y_test)))<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10010803024846956, 'fraction_numerical': 0.011163125675189053, 'mean_word_length': 6.716666666666667, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '536153', 'license': 'MIT', 'n_tokens_mistral': 995, 'n_tokens_neox': 948, 'n_words': 239, 'path': 'AI_and_ml/basic/lin-reg.ipynb', 'repo_name': 'SaicharanKandukuri/snippets-python-from-scrach', 'size': '2777'}