├── CarRentalSystem.py └── College Data Project.py /CarRentalSystem.py: -------------------------------------------------------------------------------- 1 | class Vehicle: 2 | def __init__(self, make, model): 3 | self.make = make 4 | self.model = model 5 | 6 | def make_model(self): 7 | print(f"I'm a {self.make} {self.model}.") 8 | 9 | def moves(self): 10 | print("Moves Going..") 11 | 12 | mycar = Vehicle('Tesla', 'Model 3') 13 | 14 | # print(mycar.make) 15 | # print(mycar.model) 16 | 17 | mycar.make_model() 18 | mycar.moves() 19 | 20 | 21 | your_car = Vehicle('Civi', 'Newf4') 22 | your_car.make_model() 23 | your_car.moves() 24 | 25 | class Airplane(Vehicle): 26 | def moves(self): 27 | print("File along..") 28 | 29 | class Truck(Vehicle): 30 | def moves(self): 31 | print("Truck Moving...") 32 | 33 | class moter(Vehicle): 34 | def moves(self): 35 | print("Bike Moving..") 36 | 37 | your_Airplane = Airplane('Private', 'MB29') 38 | your_Truck = Truck('G19', 'Gulish') 39 | your_moter = moter('CD-70', 'Honda') 40 | 41 | your_Airplane.make_model() 42 | your_Airplane.moves() 43 | 44 | your_Truck.make_model() 45 | your_Truck.moves() 46 | 47 | your_moter.make_model() 48 | your_moter.moves() 49 | -------------------------------------------------------------------------------- /College Data Project.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """SYED MUSTAFA HASSAN - SP24 - Intro to ML - Assignment 01 .ipynb 3 | 4 | Automatically generated by Colaboratory. 5 | 6 | Original file is located at 7 | https://colab.research.google.com/drive/15gsUQpiyq1jreVcQqD-HLdumltL-3OYi 8 | 9 | #Problem Introduction 10 | This exercise relates to the College data set, which can be found in 11 | the file College.csv on the book website. It contains a number of 12 | variables for 777 different universities and colleges in the US. The 13 | variables are 14 | * Private : Public/private indicator 15 | * Apps : Number of applications received 16 | * Accept : Number of applicants accepted 17 | * Enroll : Number of new students enrolled 18 | * Top10perc : New students from top 10 % of high school class 19 | * Top25perc : New students from top 25 % of high school class 20 | * F.Undergrad : Number of full-time undergraduates 21 | * P.Undergrad : Number of part-time undergraduates 22 | * Outstate : Out-of-state tuition 23 | * Room.Board : Room and board costs 24 | * Books : Estimated book costs 25 | * Personal : Estimated personal spending 26 | * PhD : Percent of faculty with Ph.D.s 27 | * Terminal : Percent of faculty with terminal degree 28 | * S.F.Ratio : Student/faculty ratio 29 | * perc.alumni : Percent of alumni who donate 30 | * Expend : Instructional expenditure per student 31 | * Grad.Rate : Graduation rate 32 | 33 | Before reading the data into Python, it can be viewed in Excel or a 34 | text editor. 35 | 36 | 37 | --- 38 | 39 | **Q.1** 40 | Use the pd.read_csv() function to read the data into Python. Call 41 | the loaded data college. Make sure that you have the directory 42 | set to the correct location for the data 43 | """ 44 | 45 | import numpy as np 46 | import pandas as pd 47 | 48 | Auto = pd.read_csv('College.csv') 49 | Auto 50 | 51 | """**Q.2** 52 | Look at the data used in the notebook by creating and running 53 | a new cell with just the code college in it. You should notice 54 | that the first column is just the name of each university in a 55 | column named something like Unnamed: 0. We don’t really want 56 | pandas to treat this as data. However, it may be handy to have 57 | these names for later. Try the following commands and similarly 58 | look at the resulting data frames: 59 | 60 | 61 | 62 | ``` 63 | college2 = pd.read_csv('College.csv', index_col=0) 64 | college3 = college.rename({'Unnamed: 0': 'College'}, 65 | axis=1) 66 | college3 = college3.set_index('College') 67 | ``` 68 | 69 | 70 | 71 | This has used the first column in the file as an index for the 72 | data frame. This means that pandas has given each row a name 73 | corresponding to the appropriate university. Now you should see 74 | that the first data column is Private. Note that the names of 75 | the colleges appear on the left of the table. We also introduced 76 | a new python object above: a dictionary, which is specified by 77 | (key, value) pairs. Keep your modified version of the data with 78 | the following: 79 | 80 | 81 | ``` 82 | college = college3 83 | ``` 84 | 85 | 86 | 87 | """ 88 | 89 | # college2 = pd.read_csv('College.csv', index_col=0) 90 | # college3 = college.rename({'Unnamed: 0': 'College'}, 91 | # axis=1) 92 | # college3 = college3.set_index('College') 93 | 94 | college2 = pd.read_csv('College.csv', index_col=0) 95 | 96 | college2.index.name = 'College' 97 | 98 | college = college2 99 | 100 | college 101 | 102 | """**Q.3** 103 | Use the describe() method of to produce a numerical summary 104 | of the variables in the data set. 105 | """ 106 | 107 | datasummary = college.describe() 108 | 109 | datasummary 110 | 111 | """**Q.4** 112 | Use the pd.plotting.scatter_matrix() function to produce a 113 | scatterplot matrix of the first columns [Top10perc, Apps, Enroll]. 114 | Recall that you can reference a list C of columns of a data frame 115 | A using A[C]. 116 | """ 117 | 118 | import matplotlib.pyplot as plt 119 | 120 | pd.plotting.scatter_matrix(college[['Top10perc', 'Apps', 'Enroll']]) 121 | plt.show() 122 | 123 | """**Q.5** 124 | Use the boxplot() method of college to produce side-by-side 125 | boxplots of Outstate versus Private. 126 | """ 127 | 128 | college.boxplot(column='Outstate', by='Private') 129 | plt.show() 130 | 131 | """**Q.6** 132 | Create a new qualitative variable, called Elite, by binning the 133 | Top10perc variable into two groups based on whether or not the 134 | proportion of students coming from the top 10% of their high 135 | school classes exceeds 50%. 136 | 137 | 138 | ``` 139 | college['Elite'] = pd.cut(college['Top10perc'], 140 | [0,0.5,1], 141 | labels=['No', 'Yes']) 142 | ``` 143 | Use the value_counts() method of college['Elite'] to see how 144 | many elite universities there are. Finally, use the boxplot() method 145 | again to produce side-by-side boxplots of Outstate versus Elite. 146 | 147 | """ 148 | 149 | college['Elite'] = pd.cut(college['Top10perc'], [0, 50, 100], labels=['No', 'Yes']) 150 | elite_counts = college['Elite'].value_counts() 151 | elite_boxplot = college.boxplot(column='Outstate', by='Elite') 152 | 153 | plt.show() 154 | 155 | """**Q.7** 156 | Use the plot.hist() method of college to produce some histograms with differing numbers of bins for a few of the quantitative variables. The command plt.subplots(2, 2) may be useful: it will divide the plot window into four regions so that four 157 | plots can be made simultaneously. By changing the arguments 158 | you can divide the screen up in other combinations. 159 | """ 160 | 161 | fig, axes = plt.subplots(2, 2) 162 | college['Apps'].plot.hist(ax=axes[0,0], bins=10) 163 | college['Accept'].plot.hist(ax=axes[0,1], bins=20) 164 | college['Enroll'].plot.hist(ax=axes[1,0], bins=15) 165 | college['Top10perc'].plot.hist(ax=axes[1,1], bins=5) 166 | plt.show() --------------------------------------------------------------------------------