BMAN73701 Programming in Python for Business Analytics - Week 5: Lecture 1 Intro to Machine Learning PDF

Document Details

TenderSagacity1979

Uploaded by TenderSagacity1979

The University of Manchester, Alliance Manchester Business School

Manuel López-Ibáñez

Tags

machine learning python programming business analytics data analysis

Summary

This document is a lecture from a course in programming for business analytics, focusing on the introduction to machine learning. The document covers unsupervised and supervised machine learning, along with algorithms such as K-means, decision trees, and neural networks.

Full Transcript

I MAN,CHESTER_ I 1s24 The University of Man c'hester Alliance Manchester Business Schoo BMAN73701 Programming in ~ python™for Business Analytics Python Week 5: Lecture 1 Intro to Machine Learning Prof. Manuel L...

I MAN,CHESTER_ I 1s24 The University of Man c'hester Alliance Manchester Business Schoo BMAN73701 Programming in ~ python™for Business Analytics Python Week 5: Lecture 1 Intro to Machine Learning Prof. Manuel López-Ibáñez [email protected] Office hours: Mon 4pm-5pm, Fri 9am-10am https://calendly.com/manuel-lopez-ibanez MAN,CHEsTER_ 1824 From Raw data to Data Analysis The University of Man c'hester Alliance Manchester Business Schoo Raw Data Sources Raw (Databases, Web, Acquisition Tidying Tabular Data data Excel, Text, APIs) [ Numerical ] [ Categorical ] [ Ordinal ] Preprocessing Summary stats, analysis, Data Analysis visualisation Tabular Data BMAN73701 Week 5 3 MAN,CHESTER_ What is Data? I I 1s24 The University of Man c'hester Alliance Manchester Business Schoo A dataset is a collection of numerical and/or categorical values A variable groups values that measure the ~ , same attribute, criteria, feature, dimension, … (all values will have the same type and units of measurement) , ~ Type Model Profit An observation groups the values of several variables for the same object, person, item, A New 1 experimental unit, alternative, sample, B New 2 point, ….._ C New 3 A Old 4 B Old 5 C Old 6 ~ ·~ BMAN73701 Week 5 4 MAN,CHEsTER_ 1824 Machine Learning with scikit-learn The University of Man c'hester Alliance Manchester Business Schoo Built on top of NumPy and Matplotlib  Input may be Numpy or Pandas DataFrame, Output is Numpy Open-source, free to use and contribute Keeps being updated! Object-oriented: create objects, call their methods to fit (train) them or transform other data powered by ~ Jupyter ~ Andreas C. MOiier & Sarah Guido Docs: https://scikit-learn.org/stable/index.html Examples: http://scikit-learn.org/stable/auto_examples/index.html API reference: https://scikit-learn.org/stable/api/index.html BMAN73701 Week 5 5 I MANCH ESTER 1~2---l What is Machine Learning? The Un iversity of Manchester Alliance Manchester Business Schoo,! “Given data, build a model of the features that identifies some structure in the available samples or predicts features of future samples” Machine learning == predictive analytics, statistical learning, … ML ⊂ AI however ML ≠ AI BMAN73701 Week 5 6 MANCHESTER 1824 A High-level view of ML The University of Manchester Alliance Manchester Business Schoo Unsupervised ML “Learn something without knowing any answers” Supervised ML “Given these examples of answers, learn to answer” Classification: assign categories or labels (discrete) Regression: predict a real-valued number (continuous) BMAN73701 Week 5 7 I MAN,CHESTER_ I 1s24 The University of Man c'hester Alliance Manchester Business Schoo BMAN73701 Programming in ~ python™for Business Analytics Python Week 5: Lecture 1 Intro to Machine Learning Part 1: Unsupervised ML Part 2: Supervised ML Part 3: Cross-validation MAN,CHEsTER_ 1824 Unsupervised ML The University of Man c'hester Alliance Manchester Business Schoo Data Preprocessing Inputs Outputs Tabular Data Feature Selection (Features) (Labels) Validation / Test Unsupervised Predicted ML Algorithm Outputs (Labels) Deployment phase Unsupervised Predicted New Inputs ML Algorithm Outputs (Features) (Labels) BMAN73701 Week 5 9 I MANCH ESTER 1~2---l Unsupervised ML The Un iversity of Manchester Alliance Manchester Business Schoo,! Clustering: K-means, hierarchical clustering, … – Unsupervised classification Principal Components Analysis (PCA) – Dimensionality reduction Some neural networks – Identify non-linear features – Unsupervised classification BMAN73701 Week 5 10 MAN,CHEsTER_ 1824 K-Means The University of Man c'hester Alliance Manchester Business Schoo Divide input set into K disjoint clusters, such that each cluster has center (centroid) that minimizes the distance between each point that belongs to the cluster and its centroid 𝑓2 ✓ Very well-known ✓ High-quality implementations ✓ Large number of samples 𝑓1  K must be specified  Assumes that clusters are convex and isotropic BMAN73701 Week 5 11 MANCHESTER 1824 Clustering Example..... ru N ffi 150000. 100000. ,. 50000........ 5000 10000 15000 200CHJ 25000 30000. Mean s.a1les BMAN73701 Week 5 12 MANCHESTER 1824 Clustering Example The University of Manchester Alliance Manchester Business School In : f s kl ea r- n. c l us t e r : __ 1-·-1 p :=:, 1- ~ KM ea ns 1- =,1-·-1.... kmeans3 = KMeans(n cl usters = ) X - stores [[ ]] y - krneans3.fit predict(X) y might mean that the store type (A,B,C) are influenced by mean_sales and size ar-r- ay( [1 , 0, 2, 0, 2, 0, 2, 1, 1, 1, 0, 1, 0, 0, 1, 2, 1, 200000 -..... -.... 150000 -.. - · - 100000 - - ,. 50000 -........ I 5000 10000 I I I 15000 20000 I 25,000. I - 3000( 5000......... 1 1 I I 10000 15000 20000 25000 30,000 I I Mean sa les Mean sa les BMAN73701 Week 5 13 I MANCH ESTER 1~2---l Principal Components Analysis The Un iversity of Manchester Alliance Manchester Business Schoo,! Transform the data such that the transformed data has fewer, uncorrelated features (components) that explain most of the variance of the data ✓ Visualizing high-dimensional data ✓ Reduce data with large number of features  Number of components must be specified  Often hard to understand what components represent BMAN73701 Week 5 14 MANCHESTER 1824 PCA Example The University of Manchester Alliance Manchester Business School In [ 146] : f 1- =,1--1 s kl ea n1. deeomposi tion : __i--1p =, 1-~ PCA.... X = sto r es [ [ , ]].... pe a= PCA{n _ eomponents = ).... X r = pe a.f i t t ra ns f o r m{X).... { , X. sh ape).... { X_r. sh ape) 0 r i g in al s hape : { 45 , 3) PCA sh ape : { 45 , 2) PCA of S:tores The separation of the stores in the PCA plot e 10000 ,. shows how effectively PCA 1 and 2 capture the variability in the data and represent the relationships between the stores based on the original features (sales, size, temp). e e A B C 5000 PCA 2 0 ~... - - ,5 000 ". - - 75000 - 50000 - 25000 0 25,000 5000 0 75,000 10000 0 PCA 1Week 5 BMAN73701 15 I MANCH ESTER 1~2---l Unsupervised: fit, transform, predict The Un iversity of Manchester Alliance Manchester Business Schoo,! learn the pattern in the train data model.fit(x_train) # Unsupervised Build the model: kMeans: find centroids PCA: find principal components the model learn from the train but hasn't predict anything yet BMAN73701 Week 5 16 I MANCH ESTER 1~2---l Unsupervised: fit, transform, predict The Un iversity of Manchester Alliance Manchester Business Schoo,! model.fit(x_train) # Unsupervised Build the model transform the test based on the pattern learned in fit model.transform(x_test) Transform input into a different representation: Preprocessing: scaling, normalization, encoding, … PCA: reduce dimensionality BMAN73701 Week 5 17 I MANCH ESTER 1~2---l Unsupervised: fit, transform, predict The Un iversity of Manchester Alliance Manchester Business Schoo,! model.fit(x_train) # Unsupervised Build the model model.transform(x_test) Transform input into a different representation model.predict(x_test) create prediction on the test data after its been transformed Create new output: kMeans: predict cluster for each input BMAN73701 Week 5 18 I MANCH ESTER 1~2---l Unsupervised: fit, transform, predict The Un iversity of Manchester Alliance Manchester Business Schoo,! model.fit(x_train) # Unsupervised Build the model model.transform(x_test) Transform input into a different representation model.predict(x_test) Create new output model.fit_transform() model.fit_predict() BMAN73701 Week 5 19 I MAN,CHESTER_ I 1s24 The University of Man c'hester Alliance Manchester Business Schoo BMAN73701 Programming in ~ python™for Business Analytics Python Week 5: Lecture 1 Intro to Machine Learning Part 1: Unsupervised ML Part 2: Supervised ML Part 3: Cross-validation MAN,CHEsTER_ 1824 Supervised ML Training Data The University of Man c'hester Alliance Manchester Business Schoo r~"""""""'"'"'""""'"'""""'"'"""~~... °""....-......."'"'"""~~,..... Data Preprocessing Inputs Outputs Tabular Data Feature Selection (Features) (Labels) Untrained Supervised ML Algorithm Deployment phase Trained Predicted Trained New Inputs Supervised Outputs Supervised (Features) ML Algorithm (Labels) ML Algorithm BMAN73701 Week 5 21 I MANCH ESTER 1~2---l Supervised ML The Un iversity of Manchester Alliance Manchester Business Schoo,! Multi-layer perceptron (neural network) – Regression: predict a real-valued number (continuous) Decision Trees – Classification: assign categories or labels (discrete) BMAN73701 Week 5 22 MAN,CHEsTER_ 1824 (Artificial) Neural Networks The University of Man c'hester Alliance Manchester Business Schoo transfer activation function function Bias G X4 b-1 G bias from Alvarez et al., Usefulness of artificial neural networks in the diagnosis and treatment of sleep apnea-hypopnea syndrome., 2017. Xn https://doi.org/10.5772/66570 Inputs are recombined within each hidden layer Non-linear activation function The weights determine the structure of the One hidden layer network Multi-layer perceptron (MLP) ✓ Non-linear models  Expensive / difficult to train BMAN73701 Week 5 23 MAN,CHESTER_ Deep (Artificial) Neural Networks I I 1s24 The University of Man c'hester Alliance Manchester Business Schoo hidd n tA£y r hidd n lay r 1 hidd n lay r '2 hidd n lay r 3 input lay r input L y r output tay r ✓ More layers  More capacity (complexity, prediction power, …)  Harder to train Deep Learning BMAN73701 Week 5 24 I MANCH ESTER 1~2---l Supervised: fit, transform, predict, score The Un iversity of Manchester Alliance Manchester Business Schoo,! train the model by learning the relationship between x and y model.fit(x_train, y_train) # Supervised Build the model: Neural Network (MLP): learn weights of neurons Decision tree: learn decision points/branches BMAN73701 Week 5 25 I MANCH ESTER 1~2---l Supervised: fit, predict, score The Un iversity of Manchester Alliance Manchester Business Schoo,! model.fit(x_train, y_train) # Supervised Build the model model.predict(x_test) predict the y on unseen data Create new output: Regression: predict numerical output for each input Classifiers: predict label for each input BMAN73701 Week 5 26 I MANCH ESTER 1~2---l Supervised: fit, predict, score The Un iversity of Manchester Alliance Manchester Business Schoo,! model.fit(x_train, y_train) # Supervised Build the model model.predict(x_test) Create new output: Regression: predict numerical output for each input Classifiers: predict label for each input model.score(x_test, y_test) compare the prediction and actual y Predict and compare prediction with given output: Regression: R2, … Classifiers: accuracy, … BMAN73701 Week 5 27 MANCHESTER 1824 The University of Manchester MLP Regression Alliance Manchester Business School I n. from s kl ear nmd atasets import fet ch_ ca l ifor nia_housi ng: I. "'.. hou si ng= fe t ch_ califo r nia_housi ng() I I n.," X trai n = housi ngwdata split the input (x) and output (y) "' "' "' "' "' y_trai n = housi ngwtarget " "' "' "' '" # Standardization (z-score normalization)....," from skl ear nmp re p rocessing import Sta nd ardScaler. "'. "'" sca l er= Stand ardSca l er() standardize the input/features. "'. '"'" X_trai n_s ca l ed = sca l erwfit_tra nsform(X_trai n) I n "" from s kl ear n.n e u ral_n etwork import MLPReg ressor set the model parameters...." mlp = MLPReg ressor (hidden_ laye r_si zes =50 , max_iter= 500).. "' ,, # Train ML model...... : mlp. fi t (X_t rai n_s caled, y _ trai n) fit the model to x and y train data...... : p r i nt ( "ML P rs score: mlp.. score (X_ t rai n_sca led, y _ trai n)) BJ , MLPrs score: 0.7900032989850461 get the score for the train data I n [ 13] : p ri n t ( "M~v R.2 score : u _11...... : my_R2_score(ml p. piredict (X_ trai n_s caled), y _ trai n)) My R2 score : 0. 7900032989850461 BMAN73701 Week 5 28 MAN,CHESTER_ Underfitting / Overfitting I I 1s24 The University of Man c'hester Alliance Manchester Business Schoo Hiuh Bi Lw L \V \ ari n High ri n ~------ -------~ tJn derfitting Overfitting / Tr ininu 1pl Bias trade-off Low High I d 1 mpl BMAN73701 Week 5 29 MANCHESTER 1824 Underfit / Overfit The Un iversity of Manchester Alliance Manchester Business Schoo,! High error on training data, high error on test data Underfit ? Overfit ? Other ? Underfit ! Low error on training data, high error on test data Underfit ? Overfit ? Other ? Overfit ! High error on training data, low error on test data Underfit ? Overfit ? Other ? Underfit and (bad?) luck! BMAN73701 Week 5 31 I MAN,CHESTER_ I 1s24 The University of Man c'hester Alliance Manchester Business Schoo BMAN73701 Programming in ~ python™for Business Analytics Python Week 5: Lecture 1 Intro to Machine Learning Part 1: Unsupervised ML Part 2: Supervised ML Part 3: Cross-validation MAN,CHEsTER_ 1824 Supervised ML Training Data The University of Man c'hester Alliance Manchester Business Schoo r~"""""""'"'"'""""'"'""""'"'"""~~... °""....-......."'"'"""~~,..... Data Preprocessing Inputs Outputs Tabular Data Feature Selection (Features) (Labels) Untrained Supervised ML Algorithm Deployment phase Trained Predicted Trained New Inputs Supervised Outputs Supervised (Features) ML Algorithm (Labels) ML Algorithm BMAN73701 Week 5 33 MAN,CHESTER_ Underfitting / Overfitting I I 1s24 The University of Man c'hester Alliance Manchester Business Schoo Hiuh Bi Lw L \V \ ari n High ri n ~------ -------~ tJn derfitting Overfitting / Tr ininu 1pl Bias trade-off Low High I d 1 mpl BMAN73701 Week 5 34 MAN,CHEsTER_ 1824 Supervised ML (1) Model selection The University of Man c'hester Alliance Manchester Business Schoo Data Preprocessing Inputs Outputs Tabular Data Feature Selection (Features) (Labels) Training Data Test (Validation) Data Inputs Outputs Inputs Outputs (Features) (Labels) (Features) (Labels) BMAN73701 Week 5 35 MAN,CHEsTER_ 1824 Supervised ML (2) Training The University of Man c'hester Alliance Manchester Business Schoo remove missing value Data Preprocessing Inputs Outputs Tabular Data Feature Selection (Features) (Labels) select only relevant features Training Data Test (Validation) Data Inputs Outputs Inputs Outputs (Features) (Labels) (Features) (Labels) Untrained Trained Predicted Supervised Supervised Outputs ML Algorithm ML Algorithm (Labels) model learn the relationship between x and y model make prediction of y based on x BMAN73701 Week 5 36 MAN,CHEsTER_ 1824 A simple step-by-step regression example The University of Man c'hester Training Data Alliance Manchester Business Schoo 1) Train/test random split Xtrain ytrain X y Test Data Xtest ytest 2) Train ML model Xtrain ytrain 3) Score on the test set ytest Xtest ypred output layer output layer input layer input layer hidden layer BMAN73701 Week 5 hidden layer 37 MANCHESTER 1824 The University of Manchest er Step-by-step regression example All iance Manchester Business School ## lm Split train/test from.s kl ear nw mode l.selection import trai n_te.st_.s plit X_trai n _1 X_te.st_11 y_trai n _1 y_te.st = \ trai n_te.st_.s pl it (h ou.sing.data_11 hou.si ng.target_11 test.size - 0.10) ## 2m Data Preprocessing # Standardization (z-score normalization) from s klear n.p re p rocessi ng import Stand ardSca l er # We fit the scaler on the train data and apply to both train and test scal er = Stand ar dScal er () scal er·. f it (X_trai n) learn the x_train mean and std X_trai n_ sca l e d = scal er. tra nsform (X_trai n) scale x_train so mean = 0, std =1 X_test_scal ed = sca l er. tra nsform (X_test ) scale x_test as well (but according to x_train fit) --> no data leakage ## 3. Tr·ain ML model ml p = MLPRegressor (h i dd e n_layer_sizes =100J max iter = 500) ml pw fit (X_trai n_sca l ed :, y_trai n) ## 4.. Score on tr--ain data ## 5. Score on test data ml p..score ( X_trai n_.scaled :, y _trai n) ml p..score ( X_te.st_.sca l e d , y _te.st ) Out[14 ] : 0. 80170·1 5363992394 Out [ 16 ] : 0. 7830,69113520-7399 train data score is a bit higher than test data BMAN73701 Week 5 38 MAN,CHEsTER_ 1824 QUz The University of Man c'hester Alliance Manchester Business Schoo 1. Train model A (e.g., MLP with 1 hidden layer of size 100) 2. Train model B (e.g., MLP with 2 hidden layers of size 50) 3. Score of B on test data > Score of A on test data Choose model B ? BMAN73701 Week 5 39 MANCHESTER 1824 Don’t make decisions looking at the test set although model B has better test score, its better to split the data more with validation set so that the result are more reliable BMAN73701 Week 5 40 MAN,CHEsTER_ 1824 K-fold Cross-validation The University of Man c'hester Alliance Manchester Business Schoo Training Data X y 1) Train/test random split Xtrain ytrain Test Data Xtest ytest 2) K-fold split of the training data Training Data (K-1) K-1 { folds 1 fold Xtrain ytrain Xtrain_1 ytrain_1 Validation Data Xval_1 yval_1 can get more accurate estimate for the model score Xtrain_1 ytrain_1 3) Train ML model Xval_1 yval_1 for each possible K-fold split and ypred_1 compute score on validation data input layer BMAN73701 output layer hidden layer Week 5 hidden layer 41 MAN,CHEsTER_ 1824 K-fold Cross-validation The University of Man c'hester Alliance Manchester Business Schoo Training Data X y 1) Train/test random split Xtrain ytrain Test Data Xtest ytest 2) K-fold split of the training data D Va lidat ion Set Tra ining Set Training Data (K-1) Round 1 K-1 Round 2 Xtrain Round 3 Round 10 ytrain.... Xtrain_1 ytrain_1 folds.. 1 fold Validation Data Xval_1 yval_1 Xtrain_1 ytrain_1 3) Train ML model Xval_1 yval_1 for each possible K-fold split and ypred_1 compute score on validation data input layer BMAN73701 output layer hidden layer Week 5 hidden layer 42 MANCHESTER 1824 The University of Manchester Cross-validation Alliance Manchester Business School I n : from sklearn. mode l _se l ection import c ross_val_s co re ~.. : ml p = MLPReg ressor (h i dd e n_ l ayer_sizes= SH , max_iter = 500)... : # K-fold cross-validation (this takes time!)... : scores= c ross_va l _s co re (ml p, X_trai n_s caled, y_trai n , cv - 10)... : p ri nt_c v_sco res (sco res ) 10 -fol d CV score : 0.78 ( +/ - 0. 03) I n : mlp_sma ll = MLPReg ressor· (h i dd e n_laye r'_sizes=1 , max_iter = 500) · scores= cross_val_score(ml p_s mal l , X_trai n_sca l ed, y_trai n, cv=10)... : p ri nt_cv_s co res (sco res ) 10-fol d CV score : 0.65 ( +/ - 0. 05) BMAN73701 Week 5 43 I MANCH ESTER 1~2---l K-fold Cross-validation The Un iversity of Manchester Alliance Manchester Business Schoo,!  If K is too small  faster but poor generalization too few rounds, training fold may be too small  If K is too large  takes more time, more variance, validation fold may be too small BMAN73701 Week 5 44 MAN,CHEsTER_ 1824 K-fold Cross-validation The University of Man c'hester Alliance Manchester Business Schoo Round Round Round Round Round 1 2 3 4 5 Class 0 Class 1 for classification problem only BMAN73701 Week 5 45 MAN,CHEsTER_ 1824 Stratified K-fold Cross-validation The University of Man c'hester Alliance Manchester Business Schoo Round Round Round Round Round 1 2 3 4 5 Class 0 Class 1 Stratified K-fold Round Round Round Round Round 1 2 3 4 5 Class 0 Class 1 BMAN73701 Week 5 46 I MANCH ESTER 1~2---l Stratified K-fold Cross-validation The Un iversity of Manchester Alliance Manchester Business Schoo,! For classification problems, same proportion of class labels Within train and test sets Within each fold ✓ When classes are unbalanced, use stratification: train_test_split(stratify=y_labels) cross_val_score() uses stratified k-fold CV automatically BMAN73701 Week 5 47 MANCH ESTER_ Classification: Decision Trees I I 1~2➔ The University of Man c'h ester Alliance Manchester Business Schoo Learn a hierarchy of “if/else” questions To predict: 1. Start at the top 2. Answer the question at each branch according to the input features 3. Until reaching a leaf Python  Select an output label knowledge > 50% Studied for Studied for exam > 50% exam > 90% Passed Failed Passed Failed BMAN73701 Week 5 48 I MANCH ESTER 1~2---l Classification: Decision Trees The Un iversity of Manchester Alliance Manchester Business Schoo,! Goal: Predict/understand the type of store Labels: Types are A, B and C Features: Size, Mean sales, Mean temperature 1. Encode the labels as integers 2. Split train / test 3. while NOT happy 4. Choose a DT model 5. Compute cross-validated score on train data 6. Fit chosen model on whole train set 7. Compute score on test set 8. Use the model to predict type for new data BMAN73701 Week 5 49 MANCHESTER 1824 The University of Manchester Classification with Decision Tree Alliance Manchester Business School In [ 133 ] : stores. i nfo () Int64Index: 45 ent r i es, 1 to 45 Data col umns (tota l 5 col umns): Stor e 45 non - nu ll i nt64 Type 45 non - null object Si ze 45 non- nu ll i nt64 Mean sa l es 45 non - nu ll f l oat64 Mean_Temp 45 non - nu ll f l oat64 dtypes: f l oat64 ( 2) , i nt64 ( 2) , object (1 ) memory usage: 2.1+ KB make a label for store type I n [ 134 ] : l encoder = La belE ncoder{ ). type_ encoded = l encoder-. f it t r-ans f orm {stor-es [ · Type · ] ). # Train/test split. X_ t r-a in, X_ test, y_ t r- ain, y_ test = \. t r~ain test split {stores [ [ · Size · , · Mean sa Ies · , · Mean Temp · ] ] , type_encoded, test _size = 0.10 ,. str a ti f y = type encoded) x = size, mean sales, mean temp y = encoded store type split 90-10 stratify = y BMAN73701 Week 5 50 MANCHESTER 1824 The University of Manchest er Classification with Decision Tree All iance Manchester Business School I n : from skl ear n. tree import Decision TreeC l assifier... : #Choose a DT model · dtree3 = DecisionTreeC l assi fier(criterion = ''entropy max_ depth = 3) 11 , · dt reel = Decision TreeC l assi fie r (criterion = ''entropy" , max_ depth = 1) I n : scores = cross_ va l _ score(dtree3J X_trai nJ y_trai n J cv =5)... : print_ cv_ scores(scores) 5-fold CV score : 0.85 (+/- 0.29) dtree3 has a better score I n : scores = cross_ va l _ score(dtree1J X_trai nJ y_trai n J cv =5)... : print_ cv_ score.s(scores) 5-fold CV score : 0.80 (+/- 0.20) I n : dtr·ee3. f it(X_trai nJ y_trai n)... : score = dtree3..score(X_testJ y_test) score dtree3 on the test data... : p r int (f u5core on test set: { score :..2f} 0 )... : p ri nt ( ' Predicted: ,. J dtree3. predict(X_test))... : p r·i nt ( u JJ~ctual: '' J y_test) Score on test set : 0.80 the score is similar with the test score I n [ 40,J : p ri nt ( "Predicted: "., Predicted : [2 2 0 1 0 ]... , l e nc oder. i nv erse_ tra nsform( dtree3. predict(X_ test))) Actua l : [2 1 0 1 0 ]... : p ri nt ( " Actual: "., l e ncod er.i nv erse_ tra nsform(y_ test)) Predicted : [ 'C' 'C' 'A' 'B' 'A' ] c ua l : At [ 'C' 'B' 'A' 'B' 'A' ]I BMAN73701 Week 5 51 MAN,CHEsTER_ 1824 Decision Tree The University of Man c'hester Alliance Manchester Business Schoo S~ze < = 1.39 711.0 1 s.ample,s = 40 value of class [A, B, C] V,alue = : [20,. lSi,.5 ] class = A class A has the highest value True if size

Use Quizgecko on...
Browser
Browser