Foundations of Data Science_Week 7 Notes

docx

School

Toronto Metropolitan University *

*We aren’t endorsed by this school

Course

830

Subject

Information Systems

Date

Oct 30, 2023

Type

docx

Pages

3

Uploaded by CaptainTreeNewt33

Report
Foundations of Data Science Mar 19, 2023 Module 6: Descriptive Statistics and Visualization - https://colab.research.google.com/drive/1jbT-MH_9tSA1NG_TED_yXvvAePZZimzO?usp=sharing - To important mat plot library, use the following code: import.matplot.lib.pyplot as plt Plotting with Pandas - To create a histogram , use the following code: ‘tablename.hist(bins=50, figsize=(20,15)); o Will create a histogram for every numerical column of data o Will create single data histograms - To customize a histogram , like change color, specific column data or block size, you can use the following code: tablename[“column name’].plot(kind=’hist’, figsize=(15,10), title=”column name”, color=”color”) o Example: df_housing["median_house_value"].plot(kind=’hist’, figsize=(15,10), title="Median House Value", color="green") - To save an image, use the following code: plt.gcf.savefig(“name of the image.png”) - To make a stacked histogram , use the following steps: o 1. Make a pivot table of the data columns you want to add to the stacked histogram table.pivot(columns=”column 1”)[“column 2”] o 2. Use the histogram code to create the graph table.pibot(columns=”column 1”)[“column 2”].plot(kind=’hist’, stacked = True, figsize =(15,10), title=”title of your graph”); - To make a bar plot , follow the steps below: o 1. Make a new table of the information you want to graph o 2. Use the following code to make a bar plot: ax = newtable.plot(kind=’bar’, rot = 45, figsize=(15,10)); ax.set_ylabel(“name of y axis”); ax.set+xlabel(“name of x axis”); Rot parameter rotates the labels - To make a stacked bar plot , use the following steps o 1. Make a new crosstab table with the information you want to graph df_crosstab = pd.crosstab(tablename["column 1"], table name["column 2"]) o 2. Make a stacked bar graph: ax = df.crosstab.plot(kind=’bar’, stacked = True, rot = 0, figsize=(15,10)); ax.set_ylabel(“name of y axis”); - To make a grouped bar plot , follow the steps below: o 1. Make a new table with the information you want to display df.newtable = table.groupby(“column 1”)[“column 2”, “column 3”]].function().reset_index() An example of function could be median() or mean()
Foundations of Data Science Mar 19, 2023 o 2. Make a grouped bar graph ax.df.newtable.plot(kind=’bar’, x=”column 1”, y=[“column 2”, “column 3”], rot = 0, figsize=(15,10)); ax.set_ylabel(“name of y axis”) Column 2 and 3 will be the two columns you want the grouped bar graph to show on the x axis - To make a scatter plot , use the following code: o Table.plot(kind=”scatter”, x=“column”, y=”column”, figsize=(15,10), s=2, alpha=0.8, c=”color of your choice”); S -> size of the dots on the graph Alpha -> how transparent the dots are on the graph o To zoom in on a scatter plot, add specific x-axis and y-axis ranges ax.set_xlim((#,#)) -> it will only show the data between these values on the x and y axis ax.et_ylim((#,#)) - To graph a bubble plot , look at the workbook (link at the top of document) - To make a line plot , use the following steps: o 1. Make a new table with all the information you want to graph o 2. Use the code to make a line plot: ax.df.newtable.plot(figsize=(15,10), linewidth=4) ax.set_ylabel(“name of y axis): ax.set_xlabel(“name of x axis”); plt.legend(loc=”upper/lower right/left”); -> use loc function to determine where your legend will appear on the table - To create a two line plot on the same axis, use the following code: o 1. Ax = (table[“column”].sort_values().reset_index(drop=True).plot(figsize=(15,10),linewidth=4,l abel=”name of line”); table[“column”].sort_values().reset_index(drop=True).plot(ax=ax, linewidth=4, label=”name of line”); ax.set_ylabel(“name of y axis”); ax.set_xaxis(“name of x axis”); plt.legend(loc=”location”); o Have to ensure that both lines are using the same x- axis as a reference line Plotting with Matplotlib - Histogram : plt.figure(figsize=(10,8)) plt.hist(table[“column”]) plt.title(“title of graph”) plt.ylabel(“name of y axis”) plt.xlabel(“name of x axis”) plt.savefig(“name of file.png”, dpi=180)
Foundations of Data Science Mar 19, 2023 - Scatter plot : plt.figure(figsize-(20,15)) plt.scatter( x=table[“column”, y=table[“column”], s=50, color=(o.0,0.3,0.5), -> code for the color pink; will have to google these alpha=0.5, marker=”+”, -> the symbol that appears on your graph, can use any symbol ) plt.xlabel(“name of x axis”); plt.ylabel(“name of y axis”); - Line plot : step,range=100000,1E-2 x = np.linspace(-range, range, step) display(x) plt.figure(figsize=(20,15)) plt.plot(x, np.sin(1/x), linewidth=0.1) -> #y=sin(1/x) plt.xlim(-range, range) plt.xlabel('name of x axis');plt.ylabel('name of y axis') plt.xticks(np.linspace(-range,range,7));plt.yticks(np.linspace(-1,1,7)) plt.title("title of the graph") plt.savefig("name of the file.png") - Bar plot : plt.figure(figsize=(15,20)) plt.bar(table[“column’], table[“column’], color’(color=”color of your choice”); plt.xlabel(‘name of x axis’); plt.ylabel(‘name of y axis’); - Multiple subplots and customization : refer to the workbook (link at the top of document) Plotting with Seaborn - Refer to the workbook – review each link and code
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help

Browse Popular Homework Q&A

Q: Sandeep borrows $20,000 for a new car. The bank offers him an annual interest rate of 9% compounded…
Q: the functions of families been affect by changes in society in the last 50 years
Q: Instacart offers consumers a convenient form of home delivery service for groceries. Units of output…
Q: What role can Forensic Psychologist perform as a Court Evaluator in Parental Domestics and Child…
Q: Chapter 2, exercise 10.2(a): Let H and K be subgroups of a group G. Prove that the intersection…
Q: Find the curl of the vector fieldF = curl F = %3D j+ k
Q: ed The following is a diagram of energy states and transitions in the hydrogen atom. ↑ ENERGY Use…
Q: A summer intern at the Lego factory in Billund, Denmark, samples 41 yellow bricks and 35 red bricks…
Q: Find the values of x, y and z that correspond to the critical point of the function ƒ(x, y) = 2x² +…
Q: most common methods of socialization use
Q: Apply the apriori algorithm to the following data set. Trans_id Items_purchased milk, bread, eggs…
Q: write a program in R that allows a user to do some basic math functions and return the results…
Q: 2. We wish to send 10 mA of current through the resistor R2 in the circuit below. The BJT has B=150.…
Q: 4.2. An nth root of unity is a complex number z such that z" = 1. (a) Prove that the nth roots of…
Q: Two-digit natural numbers are formed, with replacement, from the digits 0 through 9. How many…
Q: The reaction quotient (Q) for a system is 70. If Kc = 35, what will happen as equilibrium is…
Q: 8 2. Write the steps and reagents required to perform the following synthetic transformati CH3 COOH…
Q: Diamond Brands manufactures rice, wheat, and oat cereals. Sanders Company has approached Diamond…
Q: Suppose that the teacher uses a two-factor independent-measures ANOVA to analyze these data. Without…
Q: Write an equation for the function graphed below. The y intercept is at (0,-0.2) 5- 4 3D 3+ 2 1 +y =…
Q: carrybacks).
Q: 8) What is the product of the reactions below? CH3CH₂CH-CH₂ CH3CO3H A) CH3CH₂CHCH₂OCH3 ОН B)…