Commit c6df95c7 authored by root's avatar root
Browse files

lab08 complete

parent 2fd63241
%% Cell type:markdown id: tags:
# Lab 01
Name: Mitch Gavars
Class: CSCI 349 2021SP
Insructor: Brian King
%% Cell type:markdown id: tags:
##### Did you read the syllabus? All of it? Do you agree to abide by the cheating rules? Write a sentence clearly indicating your commitment to not cheating.
%% Cell type:markdown id: tags:
I will not lie, cheat, or steal in my academic endeavors.
%% Cell type:markdown id: tags:
##### What are you hoping to get out of this course?
%% Cell type:markdown id: tags:
I hope to gain a deeper understanding of data mining. The only time I have ever really talked about data mnining is when talking about ethics. I hope to understand more about it from the development side and gain an understanding of the data mining algorithms.
%% Cell type:markdown id: tags:
##### Print the Python version (available in sys package)
%% Cell type:code id: tags:
``` python
import sys
print(sys.version)
```
%% Output
3.8.5 (default, Sep 4 2020, 07:30:14)
[GCC 7.3.0]
%% Cell type:markdown id: tags:
##### Create a Python list of 10000 random integers in the range 1 to 100, using the random package. Name the list x_list.
%% Cell type:code id: tags:
``` python
import random
x_list = [random.randint(1,100) for i in range(10000)]
```
%% Cell type:markdown id: tags:
##### What is the minimum value of x_list? What is the max value? What is the mode?
%% Cell type:code id: tags:
``` python
from statistics import mode
print("The min value of x_list is: {}".format(min(x_list)))
print("The max value of x_list is: {}".format(max(x_list)))
print("The mode of x_list is: {}".format(mode(x_list)))
```
%% Output
The min value of x_list is: 1
The max value of x_list is: 100
The mode of x_list is: 3
%% Cell type:markdown id: tags:
##### Write a function to take a list of numbers as a parameter, and return the average of the list. Then, use your function to report the average value of x_list, printed as a float with 2 places of precision.
%% Cell type:code id: tags:
``` python
def average(a_list):
sum = 0
for i in range(len(a_list)):
sum += a_list[i]
avg = sum / len(a_list)
return avg
print("The average of x_list is: {:.2f}".format(average(x_list)))
```
%% Output
The average of x_list is: 50.72
%% Cell type:markdown id: tags:
##### Create a list called x_hist that represents a histogram, i.e. a distribution of the numerical data, of x_list. Each entry in x_hist should contain the range of data in widths of 10. So, x_hist[0] represents the frequency of numbers between 1-10, x_hist[1] is the frequency of numbers between 11-20, and so on. Be sure to print x_hist at the end.
%% Cell type:code id: tags:
``` python
x_hist = [0 for i in range(10)]
for i in x_list:
x_hist[(i-1)//10] += 1
print(x_hist)
```
%% Output
[978, 1000, 985, 1038, 970, 992, 987, 1047, 986, 1017]
10000
%% Cell type:markdown id: tags:
##### What is numpy? What are its strengths? Does it have any weaknesses?
%% Cell type:markdown id: tags:
numpy is a Python library. It is used to ease work with arrays in Python. I do not exactly know if numpy has weaknesses.
%% Cell type:markdown id: tags:
##### Import the numpy package as np and print the numpy version
%% Cell type:code id: tags:
``` python
import numpy as np
print(np.__version__)
# https://www.w3resource.com/python-exercises/numpy/python-numpy-exercise-1.php
# thought it was just np.version not np.__version__
```
%% Output
1.19.2
%% Cell type:markdown id: tags:
##### What is the primary object type in numpy? Can it store data of different types? Discuss.
%% Cell type:markdown id: tags:
The primary object type in numpy is an array. Just as with lists in Python, arrays in numpy can hold any data type.
%% Cell type:markdown id: tags:
##### Discuss the types of data available in numpy. You need not list every type. Just generalize, and discuss how the type system is different than the built-in types int and float in Python.
%% Cell type:markdown id: tags:
Data types in numpy consist of a lot of the same ones in Python (int, long, double, bool, etc.). The type system in numpy is different than in Python because it allows the interpretation of different types. Each data type in numpy is just a general block of information that can be interpreted as it is come across, whereas in Python each data type is its own object.
%% Cell type:markdown id: tags:
##### Create a numpy array from x_list. Reassign it as x_list. Show the contents.
%% Cell type:code id: tags:
``` python
x_list = np.array(x_list)
print(x_list)
```
%% Output
[77. 67. 41. ... 12. 49. 23.]
%% Cell type:markdown id: tags:
##### Redo the previous exercise, but set the data type of each value to 'float32'
%% Cell type:code id: tags:
``` python
x_list = np.array(x_list,'float32')
#x_list.astype('float32')
print(x_list.dtype)
```
%% Output
float32
%% Cell type:markdown id: tags:
##### Create a length 10 integer array filled with zeros
%% Cell type:code id: tags:
``` python
zeros = np.zeros(10)
print(zeros)
```
%% Output
[0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
%% Cell type:markdown id: tags:
##### Create a float array of 3 rows and 4 columns, all initialized to one.
%% Cell type:code id: tags:
``` python
ones = np.ones((3,4),'float')
print(ones)
```
%% Output
[[1. 1. 1. 1.]
[1. 1. 1. 1.]
[1. 1. 1. 1.]]
%% Cell type:markdown id: tags:
##### Create an array of 20 values, evenly spaced between 1 and 3 (HINT – look at np.linspace)
%% Cell type:code id: tags:
``` python
arr_space = np.linspace(1,3,20)
print(arr_space)
```
%% Output
[1. 1.10526316 1.21052632 1.31578947 1.42105263 1.52631579
1.63157895 1.73684211 1.84210526 1.94736842 2.05263158 2.15789474
2.26315789 2.36842105 2.47368421 2.57894737 2.68421053 2.78947368
2.89473684 3. ]
%% Cell type:markdown id: tags:
##### Set the numpy random seed to the value 12345, then create a 10 x 5 array of random integers on the interval [10, 20)
%% Cell type:code id: tags:
``` python
np.random.seed(12345)
arr_test = np.random.randint(10,20,(10,5))
print(arr_test)
```
%% Output
[[12 15 11 14 19]
[15 12 11 16 11]
[19 17 16 10 12]
[19 11 12 16 17]
[17 17 18 17 11]
[17 14 10 13 15]
[17 13 11 15 12]
[15 13 18 15 12]
[15 13 10 16 18]
[10 15 16 18 19]]
%% Cell type:code id: tags:
``` python
```
......
This diff is collapsed.