Skip to content

Instantly share code, notes, and snippets.

View infinite-Joy's full-sized avatar

Joydeep Bhattacharjee infinite-Joy

View GitHub Profile
has(jack,apples). % jack has apples.
has(jack,plums). % jack has plums.
has(ann,plums). % ann has plums.
has(dan,money). % dan has money.
fruit(apples). % apple is fruit.
fruit(plums). % plums is fruit.
/*
* usage: swipl -q -f prolog_hello.pl -t main
*/
main :-
write("Hello world!"), nl, fail.
/*
* This is a prolog code showing basic code patterns
* on how to write relationships between items and
* how to reason about them.
*/
has(jack,apples). % jack has apples.
has(jack,plums). % jack has plums.
has(ann,plums). % ann has plums.
print('##############################################')
print('normal X_test predictions are below:')
print(normal_predictions[:5])
print('......................................')
print('PCA predictions are below:')
print(predictions[:5])
print('here are the real values')
print(y_test[:5])
print('################################################')
from sklearn.decomposition import PCA
pca = PCA(n_components=2)
training_features = pca.fit_transform(X_train_scaled)
print('explained variance in train')
print(pca.explained_variance_)
clf.fit(training_features, y_train)
print('classified feature importances')
print(clf.feature_importances_)
from sklearn.preprocessing import StandardScaler
X_train_scaled = StandardScaler().fit_transform(X_train)
X_test_scaled = StandardScaler().fit_transform(X_test)
mu = X_train_scaled.mean()
print(X_train_scaled.shape)
print('mean is:')
print(mu)
clf = RandomForestClassifier(max_depth=2, random_state=0)
clf.fit(X_train, y_train)
print(clf.feature_importances_)
print('normal X_test predictions are below:')
normal_predictions = clf.predict(X_test)
print(normal_predictions[:5])
from sklearn.model_selection import train_test_split
def get_train_test(X, y, test_size):
"""Give the train and test from X and y.
To do this first combine the matrices, then split them in ratio of test_size then strip out the X and y components.
"""
y_reshaped = np.array([y.T])
combined_X_y = np.concatenate((X, y_reshaped.T), axis=1)
y = [1000] * 51 + [2000] * 55 + [3000] * 53
y = np.asarray(y)
print('some samples of y')
print(y[:5])
print('first x shape and then y shape')
print('shape of X: {}'.format(X.shape))
print('shape of y: {}'.format(y.shape))
column_names = ['Open', 'High', 'Low', 'Last', 'Close', 'Total Trade Quantity', 'Turnover (Lacs)']
X_hitech = df_hitech.loc[:, column_names].values
X_bhagyanagar = df_bhagyanar.loc[:, column_names].values
X_hudco = df_hudco.loc[:, column_names].values
X = np.concatenate([X_hitech, X_bhagyanagar, X_hudco], axis=0)
print(X[0])