Kayıtlar

Advice for applying machine learning

 import numpy as np %matplotlib widget import matplotlib.pyplot as plt from sklearn.linear_model import LinearRegression, Ridge from sklearn.preprocessing import StandardScaler, PolynomialFeatures from sklearn.model_selection import train_test_split from sklearn.metrics import mean_squared_error import tensorflow as tf from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense from tensorflow.keras.activations import relu,linear from tensorflow.keras.losses import SparseCategoricalCrossentropy from tensorflow.keras.optimizers import Adam import logging logging.getLogger("tensorflow").setLevel(logging.ERROR) from public_tests_a1 import *  tf.keras.backend.set_floatx('float64') from assigment_utils import * tf.autograph.set_verbosity(0) # Generate some data X,y,x_ideal,y_ideal = gen_data(18, 2, 0.7) print("X.shape", X.shape, "y.shape", y.shape) #split the data using sklearn routine  X_train, X_test, y_train, y_test = tra...

Decession Trees

Resim
  import pandas as pd import numpy as np import matplotlib.pyplot as plt from utils import * %matplotlib widget _ = plot_entropy() X_train = np.array([[1, 1, 1], [0, 0, 1],  [0, 1, 0],  [1, 0, 1],  [1, 1, 1],  [1, 1, 0],  [0, 0, 0],  [1, 1, 0],  [0, 1, 0],  [0, 1, 0]]) y_train = np.array([1, 1, 0, 0, 1, 1, 0, 1, 0, 0]) #For instance, the first example X_train[0] def entropy(p):     if p == 0 or p == 1:         return 0     else:         return -p * np.log2(p) - (1- p)*np.log2(1 - p)      print(entropy(0.5)) def split_indices(X, index_feature):     """Given a dataset and a index feature, return two lists for the two split nodes, the left node has the animals that have      that feature = 1 and the right node those that have the feature = 0      index feature = 0 => ear shape     index feature = 1 => face shape ...

ML development process

Resim

Bias & variance

Resim
  # for building linear regression models from sklearn.linear_model import LinearRegression, Ridge # import lab utility functions in utils.py import utils # Split the dataset into train, cv, and test x_train, y_train, x_cv, y_cv, x_test, y_test = utils.prepare_dataset('data/c2w3_lab2_data1.csv') print(f"the shape of the training set (input) is: {x_train.shape}") print(f"the shape of the training set (target) is: {y_train.shape}\n") print(f"the shape of the cross validation set (input) is: {x_cv.shape}") print(f"the shape of the cross validation set (target) is: {y_cv.shape}\n") # Preview the first 5 rows print(f"first 5 rows of the training inputs (1 feature):\n {x_train[:5]}\n") # Instantiate the regression model class model = LinearRegression() # Train and plot polynomial regression models utils.train_plot_poly(model, x_train, y_train, x_cv, y_cv, max_degree=10, baseline=400) # Train and plot polynomial regression mode...