0% found this document useful (0 votes)
31 views9 pages

DSML

Uploaded by

Madhu Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
31 views9 pages

DSML

Uploaded by

Madhu Sai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 9
import pandas as pd df=pd.read_csv("auction1.csv") display (df) PLAYER S1.No. AYER age Abdulla, 0 1 lle Abdur | Razak? Badrinath 2 3 Ke 3 4 Bailey.) 2 4 5 Dhoni,MS 2 Gambhir, 5 6 in 2 Ganguly, 6 7 yg 7 8 Kohi,V 1 Next steps: Generate code with d¥ Double-click (or enter) to edit Qi country Team PLAYING CAPTAINCY ROLE EXP SA KXIP_ Allrounder 0 BAN RCB Bowler 0 IND CSK Batsman 0 AUS CSK Batsman 1 IND CSK W. Keeper 1 IND DD+ —Batsman 1 IND KKR+ Batsman 1 IND RCB Batsman 1 © View recommended plots AVE SIXERS 0.00 0 0.00 0 32.93 28 21.00 o 37.13 64 33.31 32 25.45 42 28.26 49 AUCTION YEAR 2009 2008 2011 2009 2008 2008 2011 2011 import pandas as pd import matplotlib.pyplot as plt import seaborn as sn box=plt.boxplot(df ['SOLD PRICE']) iten.get_ydata()[0] for item in box{'caps*]] item.get_ydata()[@] for item in box[ "whiskers" ]] co[item.get_ydata()[@] for item in box[ "medians" ]] print(“Lower quartile: *,b[@]) print("Upper quartile: *,b[1]) print(*Median: ",c[@]) print("\nHighest value: ",a[1]) print (“Lowest valu ale]) print([item.get_ydata()[@] for item in box[ ‘whiskers’ ]]) print("Inter-Quartile Range:", b[1]-b[@]) print("\noutliers:") print(df{df["SOLD PRICE"]>b[1]] [["PLAYER NAME", "SOLD PRICE"]].sort_values('SOLD PRICE")) Q2 Lower quartile: 181250.@ Upper quartile: 1575000.0 Median: 675000.0 Highest value: 1800000 Lowest value: 50000 [18125¢.@, 1575000.6] Inter-Quartile Range: 1393750.0 outliers: PLAYER NAME SOLD PRICE 7 Kohli, V 1800000 1@ Tendulkar, SR 1800000 11 Yuvraj Singh 180000 1e6 175 1.50 1.25 1.00 O75 0.50 0.25 0.00 import pandas as pd import matplotlib.pyplot as plt import seaborn as sn fig, ax = plt.subplots() batsman_df = df[df ["PLAYING ROLE”] ax.scatter (x = batsman_df.SIXERS, y “Batsman"] batsman_df["SOLD PRICE"],label = "Batsman") Allrounder_df = df [df ["PLAYING ROLE"] == “Allrounder”] ax.scatter (x = Allrounder_df.SIXERS, y = Allrounder_df["SOLD PRICE"], label = “All Rounder” legendi = ax. legend(*ax.get_legend_handles_labels(), loc="upper left", title="Ranking") ax. set_xlabel ("Sixers") ax.set_ylabel("Sold Price") plt.show() influential_features = ["AVE", "SIXERS", "SOLD PRICE"] sn.pairplot(df[influential_features], height = 2) plt.show() df[influential_features] .corr() plt.show() sn.heatmap(df[influential_features].corr(), annot=True) plt.show() 106 Ranking @ Batsman @ All Rounder 175 1.50 9 q zg 8 8k 20Ud PIOS 3 4 0.25 0.00 60 20 10 Sixers suaxis 30Iud a10s AVE SIXERS SOLD PRICE 16 1.00 AVE 0.95 0.90 0.85 SIXERS 0.80 0.75 SOLD PRICE SOLD PRICE Q3 from scipy.optimize import root from math import cos from math import sin import math import scipy def eqn(x) return x*sin(x) + cos(x) xO=int(input("Enter the region where you want your nearest root: ")) myroot = scipy.optimize.root (eqn, x@) print (myroot.x[@]) Enter the region where you want your nearest root: @ 2.798386045783887 :7: DeprecationWarning: Conversion of an array with ndim return x*sin(x) + cos(x) Q4 from scipy.optimize import minimize def eqn(x) return x*#2 + 3*x + 16 y = minimize(eqn, ®, method="BFGS' ) print(y) message: Optimization terminated successfully. success: True status: @ fun: 7.75 [-1. 5200400] nit: 2 jac: [ 2.2000+00] hess_inv: [[ 5.00@e-01]] nfev: 6 njev: 3 Qs fron sklearn.datasets inport load_iris iris = load_inis() X = iris.data y = inis.target from sklearn.model_selection import train_test_split X_train, Xtest, y_train, y_test = train_test_split(X, y, test_size=0.4, random_state=1) from sklearn.neighbors inport KNeighborsClassifier kin = KNeighborsClassifier(n_neighbors=3) knn.fit(X_train, y_train) y_pred = knn.predict(x test) from sklearn import metrics print("kNN model accuracy: » metrics.accuracy_score(y_test, y_pred)) sample = [[3, 5, 4, 2], [2, 3, 5, 4]] preds = knn.predict (sample) pred_species = [iris.target_names[p] for p in preds] print("Predictions:", pred_species) kNN model accuracy: @.9833333333333333 Predictions: ['versicolor’, ‘virginica'] a6 import numpy as np vi =np.array([2,4]) v2=np.array([3,9]) print ("Vector addition: ", vi+v2) print ("Vector subtraction: ", vi-v2) print ("Vector scalar multiplication (S*v1): ", 5*v1) print ("Vector scalar multiplication (Sti): ", 5*v2) print ("Vector DOT product (vi.v2): ", vi-dot(v2)) print ("Vector length (v1 length): ", np.linalg.norm(v1)) print ("Angle between Vectors: ",np.arccos(v1.dot(v2)/(np.1inalg. norm(v1)*np. Linalg.norm(v2 vector Vector vector Vector vector Vector addition: [ 5 13] subtraction: [-1 -5] scalar multiplication (S*v1): [10 20] scalar multiplication (S*v1): [15 45] DOT product (v1.v2): 42 Length (v1 length): 4.47213595499958 Angle between Vectors: @.14189705460416438 Q7 import numpy as np A= np.array([[1 ,2 ,1], [4,4 ,5], (6,7, 7]]) B= np.array([[-7, -7, 6], [2 51-1], [4 5, -4]]) ab=np.matmul (A,B) baenp.matmul (B,A) print(ab) print(ba) result_variable = (ab == ba).all() if(result_variable Yes, AB=BA ") print else: True): print(" No ") [[1 0 @] [o1@] [9 0 4]] [[1 ee] [810] [2 01]] Yes, AB=BA

You might also like