Skip to content

Mahi - First Commit #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions helloWorld.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Hello World !

print ("Hello World !!!")
1 change: 1 addition & 0 deletions modeling/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.ipynb_checkpoints
1,466 changes: 1,466 additions & 0 deletions modeling/.ipynb_checkpoints/titanic_survival-checkpoint.ipynb

Large diffs are not rendered by default.

1,466 changes: 1,466 additions & 0 deletions modeling/titanic_survival.ipynb

Large diffs are not rendered by default.

1,784 changes: 892 additions & 892 deletions train.csv → modeling/train.csv

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions programming/numpy/.pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions programming/numpy/.pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"test/test_assesment_np.py::test_array_work",
"test/test_assesment_np.py::test_boolean_indexing"
]
Empty file.
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions programming/numpy/src/assesment_np.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@

import numpy as np

class Assesment_np:

def array_work(self, rows, cols, scalar, matrixA):
'''
INPUT: INT, INT, INT, NUMPY ARRAY
OUTPUT: NUMPY ARRAY
(of matrix product of r-by-c matrix of "scalar"'s time matrixA)
Create matrix of size (rows, cols) with elements initialized to the scalar
value. Right multiply that matrix with the passed matrixA (i.e. AB, not
BA). Return the result of the multiplication. You needn't check for
matrix compatibililty, but you accomplish this in a single line.
E.g., array_work(2, 3, 5, [[3, 4], [5, 6], [7, 8]])
[[3, 4], [[5, 5, 5],
[5, 6], * [5, 5, 5]]
[7, 8]]
'''
matrix1 = np.full((rows,cols),scalar)
return np.dot(matrixA,matrix1)

def boolean_indexing(self,arr, minimum):
'''
INPUT: NUMPY ARRAY, INT
OUTPUT: NUMPY ARRAY
(of just elements in "arr" greater or equal to "minimum")
Return an array of only the elements of "arr" that are greater than or
equal to "minimum"
Ex:
In [1]: boolean_indexing([[3, 4, 5], [6, 7, 8]], 7)
Out[1]: array([7, 8])
'''
return arr[arr>minimum]
pass
3 changes: 3 additions & 0 deletions programming/numpy/test/.pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[
"test_assesment_numpy.py::test_array_work"
]
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
41 changes: 41 additions & 0 deletions programming/numpy/test/test_assesment_np.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
from src.assesment_np import Assesment_np
import numpy as np


def test_array_work():
a = Assesment_np()
matrixA = np.array([[-4, -2],
[0, -3],
[-4, -1],
[-1, 1],
[-3, 0]])
answer1 = np.array([[-24, -24, -24],
[-12, -12, -12],
[-20, -20, -20],
[0, 0, 0],
[-12, -12, -12]])
result1 = a.array_work(2, 3, 4, matrixA)
assert (np.all(answer1 == result1))

answer2 = np.array([[-36, -36],
[-18, -18],
[-30, -30],
[0, 0],
[-18, -18]])
result2 = a.array_work(2, 2, 6, matrixA)
assert (np.all(answer2 == result2))


def test_boolean_indexing():
a = Assesment_np()
arr = np.array([[-4, -4, -3],
[-1, 16, -4],
[-3, 6, 4]])

result1 = a.boolean_indexing(arr, 0)
answer1 = np.array([16, 6, 4])
assert (np.all(result1 == answer1))

result2 = a.boolean_indexing(arr, 10)
answer2 = np.array([16])
assert (np.all(result2 == answer2))
1 change: 1 addition & 0 deletions programming/pandas/.pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions programming/pandas/.pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"test/test_assesment_panda.py::test_make_series",
"test/test_assesment_panda.py::test_data_frame_work"
]
Empty file.
Binary file not shown.
Binary file not shown.
36 changes: 36 additions & 0 deletions programming/pandas/src/assesment_panda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import numpy as np
import pandas as pd

class Assesment_panda:

def make_series(self, start, length, index):
'''
INPUTS: INT, INT, LIST (of length "length")
OUTPUT: PANDAS SERIES (of "length" sequential integers
beginning with "start" and with index "index")
Create a pandas Series of length "length" with index "index"
and with elements that are sequential integers starting from "start".
You may assume the length of index will be "length".
E.g.,
In [1]: make_series(5, 3, ['a', 'b', 'c'])
Out[1]:
a 5
b 6
c 7
dtype: int64
'''
np_array = np.arange(start,start+length)
np_lst = np.array(index)
df = pd.Series(np_array,np_lst)
return df

def data_frame_work(self,df, colA, colB, colC):
'''
INPUT: DATAFRAME, STR, STR, STR
OUTPUT: None
Insert a column (colC) into the dataframe that is the sum of colA and colB.
Assume that df contains columns colA and colB and that these are numeric.
'''
df[colC] = df[colA]+df[colB]

Empty file.
Binary file not shown.
Binary file not shown.
24 changes: 24 additions & 0 deletions programming/pandas/test/test_assesment_panda.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from src.assesment_panda import Assesment_panda
import numpy as np
import pandas as pd

def test_make_series():
a = Assesment_panda()
result = a.make_series(7, 4, ['a', 'b', 'c', 'd'])
assert (isinstance(result, pd.Series))
assert (result['a'], 7)
assert (result['d'], 10)

result = a.make_series(22, 5, ['a', 'b', 'c', 'd', 'hi'])
assert (result['a'], 22)
assert (result['d'], 25)
assert (result['hi'], 26)


def test_data_frame_work():
a = Assesment_panda()
df = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
colA, colB, colC = ('a', 'b', 'c')
a.data_frame_work(df, colA, colB, colC)
assert df[colC].tolist() == [5, 7, 9]
assert (colC in df.columns.tolist()) == True
3 changes: 3 additions & 0 deletions programming/python/.pytest_cache/v/cache/lastfailed
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"test/test_assesment_py.py::test_invert_dictionary": true
}
4 changes: 4 additions & 0 deletions programming/python/.pytest_cache/v/cache/nodeids
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[
"test/test_assesment_py.py::test_count_characters",
"test/test_assesment_py.py::test_invert_dictionary"
]
Empty file.
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions programming/python/src/assesment_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import numpy as np
class Assesment_py:

def count_characters(self,str):

'''
INPUT: STRING
OUTPUT: DICT (with counts of each character in input string)
Return a dictionary which contains
a count of the number of times each character appears in the string.
Characters which with a count of 0 should not be included in the
output dictionary.
'''
new_dic = {}
for i in str:
new_dic[i]=str.count(i)
return new_dic

def invert_dictionary(self,d):
'''
INPUT: DICT
OUTPUT: DICT (of sets of input keys indexing the same input values
indexed by the input values)
Given a dictionary d, return a new dictionary with d's values
as keys and the value for a given key being
the set of d's keys which shared the same value.
e.g. {'a': 2, 'b': 4, 'c': 2} => {2: {'a', 'c'}, 4: {'b'}}
'''
dic1={}
for i in d.values():
dic1[i]=i

for k,v in dic1.items():
dic1[k] = d.values(k)
return dic1
Empty file.
Binary file not shown.
Binary file not shown.
15 changes: 15 additions & 0 deletions programming/python/test/test_assesment_py.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from src.assesment_py import Assesment_py
import numpy as np

def test_count_characters():
a = Assesment_py()
string = "abafdcggfaabe"
answer = {"a": 4, "b": 2, "c": 1, "d": 1, "e": 1, "f": 2, "g": 2}
result = a.count_characters(string)
assert result == answer

def test_invert_dictionary():
a = Assesment_py()
d = {"a": 4, "b": 2, "c": 1, "d": 1, "e": 1, "f": 2, "g": 2}
result = {4: {'a'}, 2: {'b', 'f', 'g'}, 1: {'c', 'd', 'e'}}
assert a.invert_dictionary(d) == result