<jupyter_start><jupyter_text>Important Features plot<jupyter_code>names = np.array(Features)
importances =classifier.feature_importances_
sorted_importances = sorted(importances, reverse=True)
indices = np.argsort(-importances)
var_imp = pd.DataFrame(sorted_importances, names[indices], columns=['importance'])
list(var_imp.to_dict('dict')['importance'].keys())
fi_df = var_imp

fi_df.sort_values(by=['importance'], ascending=False,inplace=True)

plt.figure(figsize=(10,8))
sns.barplot(x=fi_df['importance'], y=list(var_imp.to_dict('dict')['importance'].keys()))
#Add chart labels
plt.title('RANDOM FOREST FEATURE IMPORTANCE')
plt.xlabel('FEATURE IMPORTANCE')
plt.ylabel('FEATURE NAMES')
imp_fea = pd.DataFrame.from_dict(var_imp)
imp_fea.to_csv('importances.csv', encoding='utf-8')<jupyter_output><empty_output><jupyter_text>Testing<jupyter_code>from feature_extraction import *

# classifier = joblib.load('rf_data_balance.pkl')
classifier = joblib.load('rf_final.pkl')

ext = Extractor()
url = "http://192.168.127.12/wordpress/wp-content/plugins/kcupikfcsj/adn/one%202"
Vector = np.array(ext(url)[:-1])
print(Vector)
prediction = classifier.predict(Vector.reshape(1, -1))
print(prediction)
black[0]
for i in black:
    Vector = np.array(ext(i['url'])).reshape(1, -1)
    
    prediction = classifier.predict(Vector )
    print(prediction)
df_origin.head()
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.sequence import pad_sequences
from tensorflow.keras.preprocessing.text import Tokenizer
import tensorflow as tf
import pickle

import random
from model import ConvModel
with open('tokenizer.pickle', 'rb') as handle:
    tokenizer = pickle.load(handle)
num_chars = len(tokenizer.word_index)+1
embedding_vector_length = 128
maxlen = 128
max_words = 20000

with tf.device('/cpu:0'):
    model_pre = "../checkpointModel/bestModelCNN"
    model = ConvModel(num_chars, embedding_vector_length, maxlen)
    model.built = True
    model.load_weights(model_pre)
def preprocess_url(url, tokenizer):
    url = url.strip()
    sequences = tokenizer.texts_to_sequences([url])
    word_index = tokenizer.word_index
    url_prepped = pad_sequences(sequences, maxlen=maxlen)
    
    return url_prepped
df_origin[0:100]
submit = []

for _ in df_origin['url'][0:100]:
#     prediction = model.predict(preprocess_url(_, tokenizer))
    submit.append(random.randint(0,1))
#     if prediction > 0.5:
#         submit.append(random.randint(0,1))
#         submit.append(1)
#     else:
#         submit.append(0)
#         submit.append(random.randint(0,1))
dataset = df_origin[0:100]
dataset['your'] = submit
dataset.to_csv("testing.csv")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13839285714285715, 'fraction_numerical': 0.02194940476190476, 'mean_word_length': 5.842239185750636, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '308636', 'license': 'MIT', 'n_tokens_mistral': 982, 'n_tokens_neox': 940, 'n_words': 153, 'path': 'Generate Dataset/Random Forest .ipynb', 'repo_name': 'aidenpearce001/Phishing-detection-ML', 'size': '2688'}