Posts

Python, a map, and a maze

Image
Python terminal maze
So I was browsing the Learn Code the Hard Way Forum and came across the concept of making a map of x y coordinates, and realized I've never actually attempted something of that nature.



So,  I fired up that Visual Studio Code ,  and had at it. 
I'm trying to figure out why I've never attempted it before.  I think I might have just decided I wasn't ready for it and skipped on to less complicated things,  but today I really could see the fun in making a maze.  While running this prompt, for screen readers, to turn off the ascii just comment out the print_ascii() calls before and in the while loop.



*The ascii map as imaged above may not print pretty in your command/terminal if the font is not the same as mine.  Change it however you want.*

There are a ton of things you could modify and change.  For example, adding a system clear screen so that the map and instructions only appear at the top.
You could add ascii colors, or shapes with ascii codes.
You c…

python statistics normal distribution continuous density

Image
Normal Distribution: Stats Class Code.



I was attempting to write the different formula's I would need for a normal distribution curve and the calculations we'd need for class.  There is a bit of success and a bit of failure in the code.  I may tweek it a bit more, so that someone could enter the a and b,  size of the curve, and the area range they want and it does the deviation, and mean calculations also, but this is enough for now.

As always, drop a comment if you see anything wrong, or that needs improvement.  Take the code, practice, break it, build it, have fun learning.

Lessons learned:
Now for this bit of code, I was sure I could use the formula I found in this Khan video to write my own python function to find the probability in a range under a curve.

Turns out, no, the math is way more complex for a continuous function.
I am leaving my function and the way it uses the formula in the code block.
I made an effort, but it failed.  I am under the assumption that scipy'…

Binomial deviation, mean, expected value, python Statistics class

Image
Binomials Deviation, Mean, Expected Value



Another stellar explanation by this Khan Academy teacher:
https://www.khanacademy.org/math/ap-statistics/random-variables-ap/binomial-mean-standard-deviation/v/finding-the-mean-and-standard-deviation-of-a-binomial-random-variable

The code has comments, but I highly encourage watching the referenced video for understanding.  I still have to look up these Bernoulli variables, and maybe check out doing something pythonistic for that too.   
So not much commentary on todays blog.

GIMME THE CODE --start code block-- # Binomial mean, deviation import math import sys # reference= https://www.khanacademy.org/math/ap-statistics/random-variables-ap/binomial-mean-standard-deviation/v/expected-value-of-binomial-variable # Binomail random variable X, is understood as: # 1) A sample set is finite # 2) The success and fail probabilities are constant, they do not change # 3) They probabilities are independant of one another. def return_ints(n, p): try: …

Stats class, binomial distribution Python

Image
A little background:

For my statistics class at the local community college, the teacher has us plug numbers into Excel to get answers, because well, we don't need to learn to do the formula.




I may be kinda a stickler about knowing the formula, while it's great Excel has a way to just plug in the numbers, I need to see the math.  I need to see and understand what's going on.

I'll come back for more testing on this, and more explanation.  The link below for khan academy will do a far superior job at explaining the math than I can.


Links
I don't know about you all, but when I looked at the SciPy and Numpy links, I had a hard time following.  Also, the formulas and methods I found return an array or an object.  I just need the result of that big hairy formula.  I must not be googling correctly.  If anyone can link me to the method in either one of these that just returns the results of that binomial distribution formula, it'd be much appreciated.  *Also, then I can…

Python, excel, pandas, write an excel file to a panda's database

Image
Using Python, Pandas and Excel to create my database

I started writing a new set of python class's for the machine learning experiment. With the original code I found that I was coding all the decisions that were being made.  Now while it functioned fine, the point of getting the machine to do the work was lost.

So the new one started trying to figure out how to make it quicker, reusable, and the data modifiable. The decision tree needed something to work with besides the hard coded solution.  This is where pandas and excel will come in.

Below the bad descisions section is the new code.  Feel free to scroll down if that's what your here for.

Image: Pandas in action.
Compacted terminal print of the columns of data labeled: size, seed_type, [...], ornaments, colors, names.   The rows are identified by number only.  1 - 8.  These identifiers in the column will help the new decision tree eliminate what plant we are describing down to a list of names that fits for size, seed_type, b…

statistics python standard deviations

I showed my statistics teacher my python file for making stem and leaf plots, and asked her if I could use the python programs I write on my stat's tests.   I was worried she'd say no, but if she didn't want me to use them, I could manage, and I would still be making them anyways, because this helps me learn. 

This is a file with three different methods/functions in it that can find your Standard Deviation of a Sample, and Standard Deviation of a Population and the z-score of a value.

# Scroll to the bottom if you just want the code#

Explanation: 

The math is not easy to explain, but basically, you want to know:
Deviation is the normal difference between the numbers in the data set and the center value - mean of all those numbers.

Mean vs Median:
 mean is the center value of all those integers like average
  median is the center data point. (which may not be a value that is close to the average/mean.

Sample vs Population:
If we wanted to know the average of ALL students in …

statistics writing data to excel file python

Another experiment inspired by Statistics class.
Excel has the tools to do this, but I'd like to find a way to do it with python and command prompt / terminal.

I don't explain much in this one, but I plan to elaborate and make it do more.  But for now, I got to nappy nap before work.  For those who have seen the prior 'write to excel' experiments and followed along, this shouldn't need too much explaining.

Here's the text for method info, which should display if a user types 'help' or '??' when a conflict occurs in data input:

format:
|__column1___ |__column2__|__column3__| ....
| row1 data   | row1 data | row1 data | ....
| row2 data   | row2 data | row2 data | ....
| ....        | .....     | ......    | ....\n
This project will ask for information to write to your excel file.
The data it will ask for ( in order ):
file_name:  the program will add the file extension for you.
number of columns in table (max 20)
name of columns or None-for no names
the nu…