Machine Learning. Dato *ML is sub part of AI. Chat gpt generative AI * Intelligence in AI comes from if it can do calculative, things easily in less time. ① Regression → predicting numbers, daily-done ② Classification → classifying individuals into classes. ③ Clustering → grouping elements based on some basis 4 Recommendation 5 Decision makings → making intelligent decisions → making machines capable of doing these 5 tasks Artificially makes AI difference between traditional programming and machine learning Most important thing for training machine is clean data * Types of machine learning 1 Supervised - The data is labelled, provided. Regression, Classification. Ex 2) Unsupervised - when data is not labelled. clustering, Ex. if we give a basket of fruit data. Recommendations it will give us groups of similar fruits 3] Reinforcement - Machine learns based on negative or positive feedback. when model is 80% Ex correct we will give second and penalty when 4] Semi-supervised - Some data is labelled and some isn't labelled. * Data Pre-processing cleaning Raw data using libraries cleaning and taking required and handling other data. handling null values. * filling null values. filling numerical column's NAN values by mean *(depends on situation) filling categorical column's NAN values by mode. * when more than 50% data is null, drop column. * data sometimes can get imbalanced by filling. model can predict biased results with such imbalance data * when we fill null data, increases uncertainty. • if filling makes column imbalance whole data then its better to delete column if it is not important for our model. Outliers - when small amount of data in the whole data set doesn't follows trend → are handled depending on task if they affect accuracy or can be made use of value which does not follows the trend. followed by other Values. * biasness - machine is biased towards one output. That should be avoided. * Variance - How far is my predicted result from actual correct result - high variance, Low variance * underfit means, model didn't learn, anything, has become biased, low variance, wrong answer on training data as well. * Overfit means model still didn't learn anything but!!! low bias pren answer training data but predicted seset ane wrong, high variance. Algorithm Encoding ding (text) Tencoding categorizal data to algo may werk on them. Label Encoder (starts with o] (numericals) na numbers, for a so that * accuracy get affected by more Categories. gives labels (numbers) to each category. Ex. male, temade, other are given Cencoded) 0,1, 2. for ② one-hot Encoder [only 0 & 1 used] for each category a feature/column is made - the column of one that category is given i and others 'o' Ex geneter Cons-Curse of dimentionality :- more dimensions of data increases possibility of model becoming overfit. pro = perfect/accurate encoding. Scaling * after exceding text data to numbers after pletting such data we might face that there is no logical distance between point but numerically there is thus we need to give one to all the data, calbed scaling problem/issue, acade Scaling is important for distance based algorithm. Input > independent variable output > dependent variable. Scaling is applied only on input/independent variable * testing a module of sklem train test-split splits data into torrining data and testing data, ratio can be decided by us. 80% train X-train when checking accuray on X-test data ue check its ansuers with y-test data 20% X-test by using matrix, metrics it compares predictions taken by model with tohle ceretual answers. These metrics are diffent for a segression and classification models. oding. *MSE = mean squared crour = diffrence between ditual answer and predicted answers Classification metrics →Accuracy en points -scale Ex gender predid Marta MM F 14 F M F f M F F M 6/8 = correct = 75% acusary. in classification we are not given error but ase given accusay M Ex⑪ min-max scalar - convert each data point in a do to. value between Scaling. There are multiple scalars. converted Values Encoding (Practical) importing Cabel-enceder from skleer ir foum steleaan preprocessing import. LabelEncecler then we fit and transform our datatab gi They are method he use fit-transform method Sealing que use Min Max Scalar to scale all data in values between o to 1. in array form. foom sklearn preprocessing import Min Max Scaler →SC = MinMax Scalar() ⇒ x = Sc. Fit transfom(x) ⇒x. * Splitting 'X' and "y' data / cdependent and indeperdent data. →x=df. (colun X=df.drop(Columns = [ "Youtput"] y = df[Youtput'] * Splitting data in training and testing data →foum sklearn, medel selection import train-test_split. que assign four variables xtrain, xtest, ytrain, ytest = train test.split(X,Y, test-size:0.2, I anadane sardomstate=True, stootify = y) Test size = percentage (Ex. 20% =0.2) of test desta random_state = Tore (model will choose training and testing dat sandomly) Stratify = only used in classification task. to maintain ratio of all categories in testing in output column. to give model the classes in which we need to classify the output. Algorithme Supervised ML K=5 generally KNN (K-nearest neighbours) → (Regression, Classification) KNN algorithm takes no. of nearest points and takes. their average to predict the point we want to procelid (test-pt) in Reegression generally nearest 5' points of test-pt.can be chengen sometimes missing values are handled by using KNN. (Canbe). takes nearest 5 points the class. in which most points are. It predicts test-pt based on majority the class that has meyority no. of Points under is predided to be test-point. K= should be odd, even valuer can result in how'r aut resulting failing to give majority. For classification task. In KNN. cehen fineling nearest 5 points from test point algorithm. calculates & its distance forum every point in dataset and then decides nearest points. * Euclidion distance formula * Manhattan distance * Hamming distance. - distance calculation between text data * cosine distance calculates angles. smaller angle means less distane between two points. means take understand the model might not select a farther pointas neermest point. * Weighted KNN - in weighted KNN # while taking average every point every point is multiplied by the reciprocal of its distance distance from the test-point. This is of its so that when data is less the model might not select a farther points as nearest point. * checking accuracy → from sklearn metrics import accurary_score → accuracy_core (ytest, pred) *increasing accuracy 4 broute, appacich completes entive touche sin code bonducte optimized approach internal algo of KNN toce algo. of liminates calculating shument andish nat posts where ptis can't be closer to test pt n-jabs: this parameter makes use of processor cores that are not invoked in any task thus to speed up distance calculations, value is given "-1" me means use all available. processor should be used. the split ports are called K-Folds Cross Validation. This type of alg splitting technique is used when we have very less data so we don't want to train-test-split where the data that is splitt in test data is test amet not used for training. To So. CV is default 5 splits data in 5 parts then one by one tacains on 4 ports and tests on 5th part for 5 times. So all the data that is available is used for training as well as * fine-tuning parameters K=n-neighbors = Ex. 19,21,23 wights = uniform, distance 7 parameter with 1 value each such that 3 values 27 times cycle is done algorithm = auto, ball-tree, kd-tree, brut n-jobs = -1 Grid-Search: takes every value of parameterhand with other 5 parameters and suns model to get highest accuracy Random-Search - Randomly takes 5 parameters with value of K. • find out best in them to get highest accuracy combination of parameters. * How to select value of K? ue sun data though a number of values of K. and observe loss of accuracy in this way loss in high at first for K=1 then it derseases et some range of value of K. and again stant increasing the elbow point we get some values of * that Should be used. * KNN Advantages : 1) Easy to implement 2] performs both Classification & regression 3) Multiclass classification can be directly possible by KNN * Drawbacks : Curse of dimensionality 2] lazy leamer 3] mandatory Scaling 4] affected by outliers. SDS Date Page No. * Gridsearch with. Cross-validation costenroq Gridsearch parameter refit: Tree means it cheeks for all combi of K. folels. with every parameter il mantini ↑ 19.8/96 * In KNN algorithm K = N-neighbour parameter should be carefully selected as it can greatly. affect accuracy of medel tund ert-bx est llod, stwo 2267 * Linear Regressions to water porous sony simple linear Regressivo = y = maxte actual pt multiple Unear Regression ymdd C 4 Ex. in Plat pricing X3 X2 in dataset it means caelghtage Arce location flosing Porice of that colern Slope=mf simputation toolas of wat ightage hig ++C = Y - intercept is the kinda lovest valere of you have if x is all o.y=maete bol anel C=010 to 2001 where to youmotove to bp wy wit C = some value y = 0 ae heve at least some min value predicted, and blows * OL'S- Ordinary least Square m=slope = 2 (xi-x). (yi-y) 4=mx+c (xi-x)² X,Y = average C=y-m.x Xi = data point. * gradient-descent = when ue case OLS the values of m and a are selected by it and the less cae have at the end between (y-y = loss) is not the lecast one and cannot be further diminished, we cannot manually use every value of mse Gradient. Descent helps us to optimise that. * Gradient-Descent :- technique used for selecting right valus form&c. ① sandomly selects values for imiand an puts in y = max te @loss-fun" = n2, (y-y)² is calculated 2 2n ⑧ then calculates da, da derivatives of manda. dm dc ④ then calculates new values for m&c by using a new m= old m-Qda & new c = old an adam dm Elearning rate dou ⑤ repeats process for new values of in and gut cont until the derivatives of m and C becomes zero and hence kew m = old m-0 -old m .newm = & new c = ddc-0 new c = old c. we get a value for m& c equal to initial m &c. hese gradient descent stops by achiving min. diffrence loss fun these values of m& C are most suitable to use as they generate min toss Idmin 2- learning rate. -proportional to the jumps of no. of times values of m & citerate. if a is very small the value of do will be very small so dm iterations are too many and vice versa.. so value of 'a' should be moderate. penalty = it acts like breates when the speed of process is fast, so in order to not exceed o. if & is high it is possible we could skip our expected ansuer and that might make our model overfit. its To avoid this me introduce Regularrization Loss Regularization 1:- in this technique every iterated vetre is added with value of m so it. m=0.800 loss=10 to Loss, = 8+0.8-8.8 (0852=6+0.8=6.8 66 stoliulos cett son This way if we ever suspass expected value adding m might get us a bit closer to missed expected value * two types in this culou wan Ridge X/m²/ 2610 bigger value m² is added so ve on get bigger breaks speeding change Eg to seduce in loss speed by 4. bigger value mis added so we go break on speeding change in loss Eg. to seduce speed by 2 * Linear Regression works on dataset which show gavesian (bell shaped curve. To handle overfitting = 0 = (9-4) + Alml+7/m²/ To achieve the 20171 curve in case of we get steered curve puis, wit of Laraitsagora ska Linear Classifier:- classifies data in tuo classes by drawing ali a line or planet Iloma it can do multiclass classificention but in the form of ivsret Ex. ABC classes ose dassified as A | BC * Logistic Regression. - Classifications y = mx + c Only perform classification. in tuo classes. uses Gradient Descent to draw a line that properly classifies tuo data into two classes. first Cine might miss classify data points but iteration of gradient descent find the best fit line that classifies data in two accurate classes for that it charges values of m & c Imagles - iter iterates and updates line. Sigmoid function is S shaped ais une. yik Egy = my te sigmoid fun" ("$(x) = 1 gistic function ၁ Sigmoid Run is S shaped When some extra data ponts aze added to desta and if they are outliers the best fil line doesn't changes the line semains same as well as its slope. its quashed to exterd horizontally. to classify these data points. in O and I also at in centre a a central limitiis taken to classify data points in (thoshiled) better for * Support Vector Machine (SVM) - Regression, Classification we stuely writ classification. • Linear classifier - classifies with line / Plane in two classes.
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )