<jupyter_start><jupyter_text>Load and clean data<jupyter_code>#load data
csv_file = 'SEEM_bile_acid_data_patient.csv'
df_patient = pd.read_csv(csv_file, index_col=None)
csv_file2 = 'SEEM_bile_acid_data_control.csv'
df_control = pd.read_csv(csv_file2, index_col = None)
csv_file3 = 'temp.csv'
biopsy_data = pd.read_csv(csv_file3)
#remove 'Barcode','CMS ID','LC/MS code#
df_control = df_control.drop(['Barcode','CMS ID','LC/MS code#'], axis=1)
df_control = df_control.groupby('Patient ID',as_index=False).mean()
df_control['Target'] = 0
#
df_patient = df_patient.drop(['Barcode','CMS ID','LC/MS code#'], axis=1)
df_patient = df_patient.groupby('Patient ID',as_index=False).mean()
df_patient['Target'] = 0<jupyter_output><empty_output><jupyter_text>Populate "Reponse" value<jupyter_code>index = []
def find_index(biopsy_data,biomaker_data):
    for i in range(0,len(biopsy_data)):
        for j in range(0,len(biomaker_data)):
            if biomaker_data['Patient ID'].loc[j] == biopsy_data['Patient ID'].loc[i]:
                index.append(j)<jupyter_output><empty_output><jupyter_text>Populdate "Response" value to patient set<jupyter_code>find_index(biopsy_data,df_patient)
index = set(index)
for val in index:
    df_patient['Target'].loc[val] = 1<jupyter_output>C:\Users\lukek\Anaconda3\lib\site-packages\pandas\core\indexing.py:189: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: http://pandas.pydata.org/pandas-docs/stable/indexing.html#indexing-view-versus-copy
  self._setitem_with_indexer(indexer, value)<jupyter_text>Populdate "Response" value to control set<jupyter_code>index = []
find_index(biopsy_data,df_control)
index = set(index)
for val in index:
    df_control['Target'].loc[val] = 1<jupyter_output><empty_output><jupyter_text>Random Forest  Random Forest to patient set<jupyter_code>df_patient = df_patient.dropna()
X = df_patient.iloc[:,1:-1]
X = X.reset_index(drop=True)
y = df_patient.iloc[:,-1]
y = y.reset_index(drop=True)
X_train, X_test, y_train, y_test = train_test_split(
...     X, y, test_size=0.33, random_state=42)
## This line instantiates the model. 
rf = RandomForestClassifier() 
## Fit the model on your training data.
rf.fit(X_train, y_train) 
## And score it on your testing data.
rf.score(X_test, y_test)
feature_importances = pd.DataFrame(rf.feature_importances_,
                                   index = X_train.columns,
                                    columns=['importance']).sort_values('importance',ascending=False)
feature_importances<jupyter_output><empty_output><jupyter_text>Random Forest to patient set<jupyter_code>df_control = df_control.dropna()
X = df_control.iloc[:,1:-1]
X = X.reset_index(drop=True)
y = df_control.iloc[:,-1]
y = y.reset_index(drop=True)
X_train, X_test, y_train, y_test = train_test_split(
...     X, y, test_size=0.33, random_state=42)
## This line instantiates the model. 
rf = RandomForestClassifier() 
## Fit the model on your training data.
rf.fit(X_train, y_train) 
## And score it on your testing data.
rf.score(X_test, y_test)
feature_importances = pd.DataFrame(rf.feature_importances_,
                                   index = X_train.columns,
                                    columns=['importance']).sort_values('importance',ascending=False)
feature_importances<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12967359050445104, 'fraction_numerical': 0.009495548961424332, 'mean_word_length': 4.976950354609929, 'pattern_counts': {'":': 0, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '487068', 'license': 'MIT', 'n_tokens_mistral': 1249, 'n_tokens_neox': 1211, 'n_words': 223, 'path': 'models/RandomForest.ipynb', 'repo_name': 'UVA-DSI-2019-Capstones/CHRC', 'size': '3370'}