├── maxi.py ├── mlday1.py ├── mllearnings.py ├── timeCheck.py └── twosum.py /maxi.py: -------------------------------------------------------------------------------- 1 | #maximum no of occurance of character; 2 | a=input() 3 | d={} 4 | for i in a: 5 | d[i]=0 6 | for i in a: 7 | d[i]+=1 8 | print(max(d.values())) 9 | -------------------------------------------------------------------------------- /mlday1.py: -------------------------------------------------------------------------------- 1 | #house price [prediciton ] 2 | size of the house --> price of the house 3 | x1---> y1 4 | learned from labels is known as supervised learning 5 | rlation btwn input and output... 6 | --> Continuous 7 | clustering ,no labels is knowm as unsuperwised learning 8 | superwised --2 types --> regression,classification 9 | optimisation ---> Gradient desent algorithm 10 | -------------------------------------------------------------------------------- /mllearnings.py: -------------------------------------------------------------------------------- 1 | """ML-LEARNINGS""" 2 | 3 | import numpy as np 4 | 5 | from time import process_time 6 | 7 | ls=[i for i in range(10000)] 8 | st=process_time() 9 | ls=[i+5 for i in ls] 10 | et=process_time() 11 | print(et-st) 12 | 13 | np_array=np.array([i for i in range(10000)]) 14 | st=process_time() 15 | np_array+=5 16 | et=process_time() 17 | print(et-st) 18 | 19 | list=[1,2,3,4] 20 | print(list) 21 | type(list) 22 | 23 | np_array= np.array([1,2,3,4,5]) 24 | print(np_array) 25 | type(np_array) 26 | 27 | #creating a 1 d array 28 | ar=np.array([1,2,3,4]) 29 | print(ar) 30 | 31 | ar.shape 32 | 33 | b=np.array([(7,8),(1,2)]) 34 | print(b) 35 | 36 | b.shape 37 | 38 | c=np.array([(1,2,3,4),(5,6,7,8)],dtype=float) 39 | print(c) 40 | 41 | x=np.zeros((4,5)) 42 | print(x) 43 | 44 | y=np.ones((4,5)) 45 | print(y) 46 | 47 | z=np.full((5,4),4) 48 | print(z) 49 | 50 | #identity matrix 51 | a=np.eye(3) 52 | print(a) 53 | 54 | #np array with random values 55 | b=np.random.random((4,3)) 56 | print(b) 57 | 58 | #array with random integers 59 | ar=np.random.randint(10,100,(3,4)) 60 | print(ar) 61 | 62 | #array of evenly spaced values--> no of values req 63 | d=np.linspace(10,30,5) 64 | print(d) 65 | 66 | # array of evenly spaced values --. specifying teh step 67 | a=np.arange(10,30,5) 68 | print(a) 69 | 70 | #convert a list to a np array 71 | lst=[1,2,34,33] 72 | ar=np.asarray(lst) 73 | print(ar) 74 | 75 | #analysing the numpy array 76 | c=np.random.randint(10,90,(5,5)) 77 | print(c) 78 | 79 | #array dimension 80 | print(c.shape) 81 | #no of dim 82 | print(c.ndim) 83 | 84 | #chck datatype of val in the array 85 | print(c.dtype) 86 | 87 | #no of elemnt sin a array 88 | print(c.size) 89 | 90 | #mathematical operations on np array 91 | lst=np.array([1,2,3,4,5]) 92 | lst2=np.array([6,7,8,9,10]) 93 | print(lst+lst2) 94 | print(lst-lst2) 95 | print(lst%lst2) 96 | 97 | ls=np.random.randint(19,222,(2,2)) 98 | ls2=np.random.randint(19,222,(2,2)) 99 | print(ls) 100 | print(ls2) 101 | print(ls+ls2) 102 | 103 | ls=np.random.randint(19,222,(2,2)) 104 | ls2=np.random.randint(19,222,(2,2)) 105 | print(ls2) 106 | print(ls) 107 | print(np.subtract(ls,ls2)) 108 | 109 | arra=np.random.randint(0,10,(2,3)) 110 | print(arra) 111 | 112 | print(np.transpose(arra)) 113 | 114 | arra=np.random.randint(0,10,(2,3)) 115 | print(arra) 116 | trans=arra.T 117 | print(trans) 118 | 119 | #reshaping the array 120 | a=np.random.randint(0,10,(2,3)) 121 | print(a) 122 | print(a.shape) 123 | b=a.reshape(3,2) 124 | print(b) 125 | 126 | import pandas as pd 127 | 128 | from sklearn.datasets import load_diabetes 129 | 130 | ds=load_diabetes(); 131 | print(ds) 132 | 133 | """#pandas dataframe 134 | df=pd.DataFrame(ds.data,columns=ds.feature_names) 135 | 136 | #pandas dataframe 137 | df=pd.DataFrame(ds.data,columns=ds.feature_names) 138 | print(df) 139 | """ 140 | 141 | df.head() 142 | 143 | df.shape 144 | 145 | #csv file to dataframe 146 | didf=pd.read_csv('/content/diabetes.csv') 147 | 148 | print(didf) 149 | didf.shape 150 | type(didf) 151 | 152 | didf.head() 153 | 154 | didf.shape 155 | 156 | #df=pd.read_excel('/content/diabetes.csv') 157 | #exporting df to a csv file 158 | df.to_csv('krish.csv') 159 | 160 | import numpy as np 161 | random=pd.DataFrame(np.random.rand(20,10)) 162 | 163 | print(random) 164 | 165 | random.head() 166 | 167 | random.shape 168 | 169 | #inspecting dataframe 170 | random.info() 171 | 172 | didf.shape 173 | 174 | didf.head() 175 | 176 | didf.tail()#last 5 rows 177 | 178 | #finding no of missing values 179 | didf.isnull().sum() 180 | 181 | # counting the values based on the values 182 | didf.value_counts('Outcome') 183 | 184 | #grp the values based on the mean 185 | didf.groupby('Outcome').mean() 186 | 187 | df.mean()#clmn 188 | 189 | didf.std() 190 | 191 | 192 | 193 | didf.count() 194 | 195 | didf.min() 196 | 197 | didf.max() 198 | 199 | didf.describe() 200 | 201 | #adding a colm to a df 202 | didf['age in df']=didf['Age']+10 203 | didf.head() 204 | 205 | #for removing particular row 206 | didf.drop(index=0,axis=0) 207 | 208 | # drop a colm 209 | didf.drop(columns='age in df',axis=1) 210 | 211 | #locating a row using index values 212 | didf.iloc[1] 213 | 214 | # locate particular colmn 215 | didf.iloc[:,0-1] 216 | 217 | #corelation(2type)+ve & -ve 218 | didf.corr() 219 | 220 | import matplotlib.pyplot as plt 221 | import numpy as np 222 | 223 | x=np.linspace(0,20,100) 224 | y=np.sin(x) 225 | z=np.cos(x) 226 | plt.plot(x,y) 227 | plt.show() 228 | plt.plot(x,z) 229 | plt.show() 230 | 231 | #adding title x-axis and y-axis labells 232 | plt.plot(x,y) 233 | plt.xlabel('angle') 234 | plt.ylabel("sin val") 235 | plt.title('Sine Wave') 236 | plt.show() 237 | 238 | x=np.linspace(-10,10,20) 239 | y=x**2 240 | plt.plot(x,y) 241 | plt.title("parabola") 242 | plt.show() 243 | 244 | plt.plot(x,y,'r--') 245 | plt.show() 246 | 247 | x=np.linspace(-5,5,50) 248 | plt.plot(x,np.sin(x),'g*') 249 | plt.plot(x,np.cos(x),'r+') 250 | plt.show() 251 | 252 | flg=plt.figure() 253 | ax1=flg.add_axes([0,0,1,1]) 254 | lan=['eng','fren','hin','span','latin'] 255 | pple=[10,23,44,55,44] 256 | plt.bar(lan,pple) 257 | plt.show() 258 | 259 | fig1=plt.figure() 260 | acx1=fig1.add_axes([0,0,1,1]) 261 | lan=['eng','fren','hin','span','latin'] 262 | pple=[10,23,44,55,44] 263 | acx1.pie(pple,labels=lan,autopct="%1.1f%%") 264 | plt.show() 265 | 266 | # scatter plot 267 | x=np.linspace(0,10,30) 268 | y=np.sin(x) 269 | z=np.cos(x) 270 | fig2=plt.figure() 271 | ax1=fig2.add_axes([0,0,1,1]) 272 | plt.scatter(x,y,color='g') 273 | plt.scatter(x,z,color='r') 274 | plt.show() 275 | 276 | #3d scatter plot 277 | fig3=plt.figure() 278 | ax=plt.axes(projection='3d') 279 | z=20*np.random.random(100) 280 | x=np.sin(z) 281 | y=np.cos(z) 282 | ax.scatter3D(x,y,z,color='b') 283 | 284 | import seaborn as sns 285 | import matplotlib.pyplot as plt 286 | import pandas as pd 287 | import numpy as np 288 | 289 | tips=sns.load_dataset('tips') 290 | print(tips) 291 | 292 | tips.head( ) 293 | 294 | sns.relplot(data=tips,x='total_bill',y='tip',col='time',hue='smoker',style='smoker',size='size') 295 | 296 | #setting a theme for the plt 297 | sns.set_theme(style='darkgrid') 298 | 299 | sns.relplot(data=tips,x='total_bill',y='tip',col='time',hue='smoker',style='smoker',size='size') 300 | 301 | #loading iris dataset 302 | iris=sns.load_dataset('iris') 303 | iris.head() 304 | 305 | #scatter plt 306 | sns.scatterplot(x='sepal_length',y='petal_length',hue='species',data=iris) 307 | 308 | #scatter plt 309 | sns.scatterplot(x='sepal_length',y='petal_width',hue='species',data=iris) 310 | 311 | #loading the titanic dataset 312 | tit=sns.load_dataset('titanic') 313 | tit.head() 314 | 315 | #Count plot 316 | sns.countplot(x='class',data=tit) 317 | 318 | sns.countplot(x='survived',data=tit) 319 | 320 | #bar 321 | sns.barplot(x='sex',y='survived',hue='class',data=tit) 322 | 323 | #house price predict 324 | from sklearn.datasets import load_diabetes 325 | db=load_diabetes() 326 | 327 | hou=pd.DataFrame(db.data,columns=db.feature_names) 328 | hou['prize']=db.target 329 | hou.head() 330 | 331 | sns.distplot(hou['bmi']) 332 | 333 | plt.figure(figsize=(10,10)) 334 | 335 | sns.heatmap(hou.corr(),cbar=True,square=True,fmt='.1f', annot=True,annot_kws={'size':8},cmap='Blues') 336 | -------------------------------------------------------------------------------- /timeCheck.py: -------------------------------------------------------------------------------- 1 | from time import process_time 2 | ls=[i for i in range(0,10000)] 3 | st=process_time() 4 | ls=[i+5 for i in ls] 5 | et=process_time() 6 | print(et-st) 7 | -------------------------------------------------------------------------------- /twosum.py: -------------------------------------------------------------------------------- 1 | a=list(map(int,input().split())) 2 | b=int(input()) 3 | for i in range(0,len(a)): 4 | for j in range(i+1,len(a)): 5 | if a[i]+a[j]==b: 6 | print(f"[{i}, {j}]") 7 | break 8 | --------------------------------------------------------------------------------