import numpy as np import pandas as pd import matplotlib.pyplot as plt import seaborn as sns data_raw = pd.read_csv("https://jonghank.github.io/ase3001/files/falcon9_launch_data_raw.csv") data_raw data_raw['LaunchSite'].value_counts() data_raw['Orbit'].value_counts() landing_outcomes = data_raw['Outcome'].value_counts() landing_outcomes sns.catplot(y="PayloadMass", x="FlightNumber", hue="Class", \ data=data_raw, aspect = 5) plt.xlabel("Flight Number",fontsize=20) plt.ylabel("Pay load Mass (kg)",fontsize=20) plt.show() sns.catplot(y='LaunchSite', x='FlightNumber', hue='Class', \ data=data_raw, aspect=5) plt.xlabel("Flight Number",fontsize=20) plt.ylabel("LaunchSite",fontsize=20) plt.show() sns.catplot(y='LaunchSite', x='PayloadMass', hue='Class', \ data=data_raw, aspect=5) plt.xlabel("Pauload Mass(Kg)",fontsize=20) plt.ylabel("LaunchSite",fontsize=20) plt.show() df_success=data_raw.groupby('Orbit')['Class'].mean()*100 df_success.plot(kind='bar', figsize=(10,6)) plt.xlabel('Orbit') plt.ylabel('Success Rate') plt.title('Relationship between Success Rate and Orbit') plt.show() sns.catplot(y='Orbit', x='FlightNumber', hue='Class', \ data=data_raw, aspect=5) plt.xlabel("Flight Number",fontsize=20) plt.ylabel("Orbit",fontsize=20) plt.show() sns.catplot(y='Orbit', x='PayloadMass', hue='Class', \ data=data_raw, aspect=5) plt.xlabel("Pauload Mass(Kg)",fontsize=20) plt.ylabel("Orbit",fontsize=20) plt.show() data_raw['Date'] = data_raw['Date'].astype(str) year=[] def Extract_year(df): for i in data_raw["Date"]: year.append(i.split("-")[0]) return year Extract_year(data_raw) data_raw['Year']=year fig,ax=plt.subplots() df_success1=data_raw.groupby('Year')['Class'].mean()*100 df_success1.plot(kind='line', figsize=(10,6)) plt.xlabel('Year') plt.ylabel('Success Rate') plt.title('Relationship between Success Rate and Year') plt.grid() plt.show() features = data_raw[['FlightNumber', 'PayloadMass', 'Orbit', \ 'LaunchSite', 'Flights', 'GridFins', \ 'Reused', 'Legs', 'LandingPad', 'Block', \ 'ReusedCount', 'Serial']] features data = pd.read_csv("https://jonghank.github.io/ase3001/files/falcon9_dataset.csv") data X = data.iloc[:,:-1].to_numpy() y = data.iloc[:,-1].to_numpy()*2 - 1 N = len(y) rand_ind = list(range(N)) np.random.seed(3001) np.random.shuffle(rand_ind) N_train = int(N*0.8) X_train = X[rand_ind[:N_train]] y_train = y[rand_ind[:N_train]] X_test = X[rand_ind[N_train:]] y_test = y[rand_ind[N_train:]] def solve_svm(X, y, lam=1): import cvxpy as cp w = cp.Variable(X.shape[1]) b = cp.Variable() obj = cp.sum(cp.pos(1-cp.multiply(y,(X@w-b)))) reg = cp.sum_squares(w) problem = cp.Problem(cp.Minimize(obj + lam*reg)) problem.solve(solver=cp.CLARABEL) return w.value, b.value, obj.value, reg.value # your code here def solve_logistic_regression(X, y, lam=1): import cvxpy as cp w = cp.Variable(X.shape[1]) b = cp.Variable() obj = cp.sum(cp.logistic(-cp.multiply(y,(X@w-b)))) reg = cp.sum_squares(w) problem = cp.Problem(cp.Minimize(obj + lam*reg)) problem.solve(solver=cp.CLARABEL) return w.value, b.value, obj.value, reg.value # your code here