Skip to content

Conversation

@sourcery-ai
Copy link

@sourcery-ai sourcery-ai bot commented May 4, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from edson-github May 4, 2023 21:18
Comment on lines -30 to +36

x=resp.json()
j = json.loads(x)
d = dict(j)

for k,v in (d.items()):
print("{}: {}".format(k,round(v,2)))
print(f"{k}: {round(v, 2)}")
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 30-36 refactored with the following changes:

Comment on lines -24 to +41
clf = 'lm_model_v1.pk'

if test.empty:
return(bad_request())
else:
#Load the saved model
print("Loading the model...")
loaded_model = None
with open('./models/'+clf,'rb') as f:
loaded_model = pickle.load(f)

print("The model has been loaded...doing predictions now...")
print()
predictions = loaded_model.predict(test)

prediction_series = pd.Series(predictions)
response = jsonify(prediction_series.to_json())
response.status_code = 200
return (response)
#Load the saved model
print("Loading the model...")
loaded_model = None
clf = 'lm_model_v1.pk'

with open(f'./models/{clf}', 'rb') as f:
loaded_model = pickle.load(f)

print("The model has been loaded...doing predictions now...")
print()
predictions = loaded_model.predict(test)

prediction_series = pd.Series(predictions)
response = jsonify(prediction_series.to_json())
response.status_code = 200
return (response)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function apicall refactored with the following changes:

import pandas as pd

import os
import os
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 4-97 refactored with the following changes:

# Keep adding new words
for i in range(new_words):

for _ in range(new_words):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generate_random_start refactored with the following changes:

This removes the following comments ( why? ):

#return f"<div>{seed_html}</div><div>{gen_html}</div><div>{a_html}</div>"
# Showing generated and actual abstract

Comment on lines -99 to +87
word_idx = json.load(open('data/word-index.json'))
word_idx = json.load(open('data/word-index.json'))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function generate_from_seed refactored with the following changes:

Comment on lines -56 to +49
for i in range(len(y)):
for _ in range(len(y)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function flip refactored with the following changes:

Comment on lines -82 to +102
if m==None:

if m is None:
m=''
for i in range(1,n_features+1):
c='x'+str(i)
c = f'x{str(i)}'
c+=np.random.choice(['+','-'],p=[0.5,0.5])
m+=c
m=m[:-1]
sym_m=sympify(m)
n_features=len(sym_m.atoms(Symbol))
evals=[]
lst_features=[]
for i in range(n_features):
lst_features.append(np.random.normal(scale=5,size=n_samples))
lst_features = [
np.random.normal(scale=5, size=n_samples) for _ in range(n_features)
]
lst_features=np.array(lst_features)
lst_features=lst_features.T
for i in range(n_samples):
evals.append(eval_multinomial(m,vals=list(lst_features[i])))

evals = [
eval_multinomial(m, vals=list(lst_features[i]))
for i in range(n_samples)
]
evals=np.array(evals)
evals_binary=evals>0
evals_binary=evals_binary.flatten()
evals_binary=np.array(evals_binary,dtype=int)
evals_binary=flip(evals_binary,p=flip_y)
evals_binary=evals_binary.reshape(n_samples,1)

lst_features=lst_features.reshape(n_samples,n_features)
x=np.hstack((lst_features,evals_binary))

return (x)
return np.hstack((lst_features,evals_binary))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gen_classification_symbolic refactored with the following changes:

Comment on lines -134 to +149
if m==None:

if m is None:
m=''
for i in range(1,n_features+1):
c='x'+str(i)
c = f'x{str(i)}'
c+=np.random.choice(['+','-'],p=[0.5,0.5])
m+=c
m=m[:-1]

sym_m=sympify(m)
n_features=len(sym_m.atoms(Symbol))
evals=[]
lst_features=[]

for i in range(n_features):
lst_features.append(np.random.normal(scale=5,size=n_samples))
lst_features = [
np.random.normal(scale=5, size=n_samples) for _ in range(n_features)
]
lst_features=np.array(lst_features)
lst_features=lst_features.T
lst_features=lst_features.reshape(n_samples,n_features)

for i in range(n_samples):
evals.append(eval_multinomial(m,vals=list(lst_features[i])))


evals = [
eval_multinomial(m, vals=list(lst_features[i]))
for i in range(n_samples)
]
evals=np.array(evals)
evals=evals.reshape(n_samples,1)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gen_regression_symbolic refactored with the following changes:

Comment on lines -280 to +283
df = pd.DataFrame(np.random.normal(loc=5,
scale=5, size=50).reshape(10, 5),
columns = ['A'+ str(i) for i in range(1, 6)])
df = pd.DataFrame(
np.random.normal(loc=5, scale=5, size=50).reshape(10, 5),
columns=[f'A{str(i)}' for i in range(1, 6)],
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 280-317 refactored with the following changes:

```
x = st.slider('x', -8, 8)
"""

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 414-414 refactored with the following changes:

s3=sympify(s2)

return(s3)
return sympify(s2)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function symbolize refactored with the following changes:

Comment on lines -22 to +20
sym_lst=[]
for s in sym_set:
sym_lst.append(str(s))
sym_lst = [str(s) for s in sym_set]
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function eval_multinomial refactored with the following changes:

Comment on lines -50 to +43
for i in range(len(y)):
for _ in range(len(y)):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function flip refactored with the following changes:

Comment on lines -72 to +91
if m==None:
if m is None:
m=''
for i in range(1,n_features+1):
c='x'+str(i)
c = f'x{str(i)}'
c+=np.random.choice(['+','-'],p=[0.5,0.5])
m+=c
m=m[:-1]
sym_m=sympify(m)
n_features=len(sym_m.atoms(Symbol))
evals=[]
lst_features=[]
for i in range(n_features):
lst_features.append(np.random.normal(scale=5,size=n_samples))
lst_features = [
np.random.normal(scale=5, size=n_samples) for _ in range(n_features)
]
lst_features=np.array(lst_features)
lst_features=lst_features.T
for i in range(n_samples):
evals.append(eval_multinomial(m,vals=list(lst_features[i])))

evals = [
eval_multinomial(m, vals=list(lst_features[i]))
for i in range(n_samples)
]
evals=np.array(evals)
evals_binary=evals>0
evals_binary=evals_binary.flatten()
evals_binary=np.array(evals_binary,dtype=int)
evals_binary=flip(evals_binary,p=flip_y)
evals_binary=evals_binary.reshape(n_samples,1)

lst_features=lst_features.reshape(n_samples,n_features)
x=np.hstack((lst_features,evals_binary))

return (x)
return np.hstack((lst_features,evals_binary))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gen_classification_symbolic refactored with the following changes:

Comment on lines -119 to +133
if m==None:
if m is None:
m=''
for i in range(1,n_features+1):
c='x'+str(i)
c = f'x{str(i)}'
c+=np.random.choice(['+','-'],p=[0.5,0.5])
m+=c
m=m[:-1]

sym_m=sympify(m)
n_features=len(sym_m.atoms(Symbol))
evals=[]
lst_features=[]

for i in range(n_features):
lst_features.append(np.random.normal(scale=5,size=n_samples))
lst_features = [
np.random.normal(scale=5, size=n_samples) for _ in range(n_features)
]
lst_features=np.array(lst_features)
lst_features=lst_features.T
lst_features=lst_features.reshape(n_samples,n_features)

for i in range(n_samples):
evals.append(eval_multinomial(m,vals=list(lst_features[i])))


evals = [
eval_multinomial(m, vals=list(lst_features[i]))
for i in range(n_samples)
]
evals=np.array(evals)
evals=evals.reshape(n_samples,1)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function gen_regression_symbolic refactored with the following changes:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant