1381 lines
168 KiB
Plaintext
1381 lines
168 KiB
Plaintext
|
{
|
|||
|
"cells": [
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"import all usefull tool"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 1,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"Populating the interactive namespace from numpy and matplotlib\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"%pylab inline\n",
|
|||
|
"\n",
|
|||
|
"import pandas as pd\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"import itertools\n",
|
|||
|
"from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer, HashingVectorizer\n",
|
|||
|
"from sklearn.model_selection import train_test_split\n",
|
|||
|
"from sklearn.linear_model import PassiveAggressiveClassifier\n",
|
|||
|
"from sklearn.naive_bayes import MultinomialNB\n",
|
|||
|
"from sklearn import metrics\n",
|
|||
|
"import matplotlib.pyplot as plt"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Read in Datasets"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Load Dataset 1 - fake_or_real_news.csv\n",
|
|||
|
"Read in File fake_or_real_news.csv"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 2,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"df = pd.read_csv('/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/fake_or_real_news.csv')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"ignores first column"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 3,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"df = df.set_index('Unnamed: 0')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"quick view at the data"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 4,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style>\n",
|
|||
|
" .dataframe thead tr:only-child th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: left;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>title</th>\n",
|
|||
|
" <th>text</th>\n",
|
|||
|
" <th>label</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>Unnamed: 0</th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th></th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>8476</th>\n",
|
|||
|
" <td>You Can Smell Hillary’s Fear</td>\n",
|
|||
|
" <td>Daniel Greenfield, a Shillman Journalism Fello...</td>\n",
|
|||
|
" <td>FAKE</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>10294</th>\n",
|
|||
|
" <td>Watch The Exact Moment Paul Ryan Committed Pol...</td>\n",
|
|||
|
" <td>Google Pinterest Digg Linkedin Reddit Stumbleu...</td>\n",
|
|||
|
" <td>FAKE</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3608</th>\n",
|
|||
|
" <td>Kerry to go to Paris in gesture of sympathy</td>\n",
|
|||
|
" <td>U.S. Secretary of State John F. Kerry said Mon...</td>\n",
|
|||
|
" <td>REAL</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>10142</th>\n",
|
|||
|
" <td>Bernie supporters on Twitter erupt in anger ag...</td>\n",
|
|||
|
" <td>— Kaydee King (@KaydeeKing) November 9, 2016 T...</td>\n",
|
|||
|
" <td>FAKE</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>875</th>\n",
|
|||
|
" <td>The Battle of New York: Why This Primary Matters</td>\n",
|
|||
|
" <td>It's primary day in New York and front-runners...</td>\n",
|
|||
|
" <td>REAL</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" title \\\n",
|
|||
|
"Unnamed: 0 \n",
|
|||
|
"8476 You Can Smell Hillary’s Fear \n",
|
|||
|
"10294 Watch The Exact Moment Paul Ryan Committed Pol... \n",
|
|||
|
"3608 Kerry to go to Paris in gesture of sympathy \n",
|
|||
|
"10142 Bernie supporters on Twitter erupt in anger ag... \n",
|
|||
|
"875 The Battle of New York: Why This Primary Matters \n",
|
|||
|
"\n",
|
|||
|
" text label \n",
|
|||
|
"Unnamed: 0 \n",
|
|||
|
"8476 Daniel Greenfield, a Shillman Journalism Fello... FAKE \n",
|
|||
|
"10294 Google Pinterest Digg Linkedin Reddit Stumbleu... FAKE \n",
|
|||
|
"3608 U.S. Secretary of State John F. Kerry said Mon... REAL \n",
|
|||
|
"10142 — Kaydee King (@KaydeeKing) November 9, 2016 T... FAKE \n",
|
|||
|
"875 It's primary day in New York and front-runners... REAL "
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 4,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"df.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"store label from tob row of the table"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 5,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"#store label before dropping it\n",
|
|||
|
"bin_y = df.label\n",
|
|||
|
"#y.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"cut of label column to get an unlabled array"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 6,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"df = df.drop('label', axis=1)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"from skikit learn the function: train_test_split\n",
|
|||
|
"* in the dataframe get text column by df['text']\n",
|
|||
|
"* use stored y label df\n",
|
|||
|
"* use seed 42\n",
|
|||
|
"* determine split size: in this case 0.33"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 7,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"bin_X_train, bin_X_test, bin_y_train, bin_y_test = train_test_split(df['text'], bin_y, test_size=0.25, random_state=4222)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Load Dataset 2 - liar_dataset.zip\n",
|
|||
|
"Read in File liar_dataset.zip"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 8,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"#training data file\n",
|
|||
|
"df = pd.read_csv('/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/train.tsv', delimiter=\"\\t\", header=None, usecols=[1,2], names=['y', 'claim'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 9,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style>\n",
|
|||
|
" .dataframe thead tr:only-child th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: left;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>y</th>\n",
|
|||
|
" <th>claim</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>false</td>\n",
|
|||
|
" <td>Says the Annies List political group supports ...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>half-true</td>\n",
|
|||
|
" <td>When did the decline of coal start? It started...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>mostly-true</td>\n",
|
|||
|
" <td>Hillary Clinton agrees with John McCain \"by vo...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>false</td>\n",
|
|||
|
" <td>Health care reform legislation is likely to ma...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>half-true</td>\n",
|
|||
|
" <td>The economic turnaround started at the end of ...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" y claim\n",
|
|||
|
"0 false Says the Annies List political group supports ...\n",
|
|||
|
"1 half-true When did the decline of coal start? It started...\n",
|
|||
|
"2 mostly-true Hillary Clinton agrees with John McCain \"by vo...\n",
|
|||
|
"3 false Health care reform legislation is likely to ma...\n",
|
|||
|
"4 half-true The economic turnaround started at the end of ..."
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 9,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"df.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 10,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mul_X_train = df.claim\n",
|
|||
|
"mul_y_train = df.y"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 11,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"#test data file\n",
|
|||
|
"df = pd.read_csv('/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/test.tsv', delimiter=\"\\t\", header=None, usecols=[1,2], names=['y', 'claim'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 12,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/html": [
|
|||
|
"<div>\n",
|
|||
|
"<style>\n",
|
|||
|
" .dataframe thead tr:only-child th {\n",
|
|||
|
" text-align: right;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe thead th {\n",
|
|||
|
" text-align: left;\n",
|
|||
|
" }\n",
|
|||
|
"\n",
|
|||
|
" .dataframe tbody tr th {\n",
|
|||
|
" vertical-align: top;\n",
|
|||
|
" }\n",
|
|||
|
"</style>\n",
|
|||
|
"<table border=\"1\" class=\"dataframe\">\n",
|
|||
|
" <thead>\n",
|
|||
|
" <tr style=\"text-align: right;\">\n",
|
|||
|
" <th></th>\n",
|
|||
|
" <th>y</th>\n",
|
|||
|
" <th>claim</th>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </thead>\n",
|
|||
|
" <tbody>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>0</th>\n",
|
|||
|
" <td>true</td>\n",
|
|||
|
" <td>Building a wall on the U.S.-Mexico border will...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>1</th>\n",
|
|||
|
" <td>false</td>\n",
|
|||
|
" <td>Wisconsin is on pace to double the number of l...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>2</th>\n",
|
|||
|
" <td>false</td>\n",
|
|||
|
" <td>Says John McCain has done nothing to help the ...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>3</th>\n",
|
|||
|
" <td>half-true</td>\n",
|
|||
|
" <td>Suzanne Bonamici supports a plan that will cut...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" <tr>\n",
|
|||
|
" <th>4</th>\n",
|
|||
|
" <td>pants-fire</td>\n",
|
|||
|
" <td>When asked by a reporter whether hes at the ce...</td>\n",
|
|||
|
" </tr>\n",
|
|||
|
" </tbody>\n",
|
|||
|
"</table>\n",
|
|||
|
"</div>"
|
|||
|
],
|
|||
|
"text/plain": [
|
|||
|
" y claim\n",
|
|||
|
"0 true Building a wall on the U.S.-Mexico border will...\n",
|
|||
|
"1 false Wisconsin is on pace to double the number of l...\n",
|
|||
|
"2 false Says John McCain has done nothing to help the ...\n",
|
|||
|
"3 half-true Suzanne Bonamici supports a plan that will cut...\n",
|
|||
|
"4 pants-fire When asked by a reporter whether hes at the ce..."
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 12,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"df.head()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 13,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mul_X_test = df.claim\n",
|
|||
|
"mul_y_test = df.y"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 14,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"#test data file\n",
|
|||
|
"df = pd.read_csv('/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/valid.tsv', delimiter=\"\\t\", header=None, usecols=[1,2], names=['y', 'claim'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 15,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mul_X_valid = df.claim\n",
|
|||
|
"mul_y_valid = df.y"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 16,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"<class 'pandas.core.series.Series'>\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"print(type(mul_X_valid))"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Generate Dataset 3\n",
|
|||
|
"* using code from Diego by copy paste with some small modifications\n",
|
|||
|
"* thanks for distributing this code @diego ;)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 17,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"-- fake news\n",
|
|||
|
"Index(['y', 'claim'], dtype='object')\n",
|
|||
|
"3171\n",
|
|||
|
"3164\n",
|
|||
|
"6335\n",
|
|||
|
"-- liar liar\n",
|
|||
|
"Index(['y', 'claim'], dtype='object')\n",
|
|||
|
"{'mostly-true', 'pants-fire', 'true', 'half-true', 'false', 'barely-true'} 10240\n",
|
|||
|
"1676\n",
|
|||
|
"1995\n",
|
|||
|
"{'true', 'false'} 3671\n",
|
|||
|
"false 5159\n",
|
|||
|
"true 4847\n",
|
|||
|
"Name: y, dtype: int64\n",
|
|||
|
"done\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"'''import random\n",
|
|||
|
"import sys\n",
|
|||
|
"import pandas as pd\n",
|
|||
|
"import numpy as np\n",
|
|||
|
"from sklearn.cross_validation import train_test_split\n",
|
|||
|
"\n",
|
|||
|
"ds1 = sys.argv[1]\n",
|
|||
|
"ds2 = sys.argv[2]'''\n",
|
|||
|
"\n",
|
|||
|
"try:\n",
|
|||
|
" print('-- fake news')\n",
|
|||
|
" df1 = pd.read_csv('/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/fake_or_real_news.csv', sep=',', usecols=['title','text','label'])\n",
|
|||
|
" df1['claim'] = df1[['title', 'text']].apply(lambda x: '. '.join(x), axis=1)\n",
|
|||
|
" del df1['title']\n",
|
|||
|
" del df1['text']\n",
|
|||
|
" df1.rename(index=str, columns={'label': 'y'}, inplace=True)\n",
|
|||
|
" print(df1.keys())\n",
|
|||
|
" print(len(df1[df1['y']=='REAL']))\n",
|
|||
|
" print(len(df1[df1['y']=='FAKE']))\n",
|
|||
|
" df1['y'] = np.where(df1['y'] == 'FAKE', 'false', 'true')\n",
|
|||
|
" print(len(df1))\n",
|
|||
|
"\n",
|
|||
|
" print('-- liar liar')\n",
|
|||
|
" df2 = pd.read_csv('/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/train.tsv', sep='\\t', header=None, usecols=[1,2], names=['y', 'claim'])\n",
|
|||
|
" print(df2.keys())\n",
|
|||
|
" print(set(df2.y), len(df2))\n",
|
|||
|
" print(len(df2[df2['y'] == 'true']))\n",
|
|||
|
" print(len(df2[df2['y'] == 'false']))\n",
|
|||
|
" df2=df2[(df2['y'] == 'true') | (df2['y'] == 'false')]\n",
|
|||
|
" print(set(df2.y), len(df2))\n",
|
|||
|
"\n",
|
|||
|
" df3=pd.concat([df1, df2], ignore_index=True)\n",
|
|||
|
"\n",
|
|||
|
" print(df3['y'].value_counts())\n",
|
|||
|
" print('done')\n",
|
|||
|
" concat_X_train, concat_X_test, concat_y_train, concat_y_test = train_test_split(df3['claim'], df3['y'], test_size=0.25, random_state=4222)\n",
|
|||
|
" \n",
|
|||
|
" \n",
|
|||
|
"except Exception as e:\n",
|
|||
|
" print(e)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Vectorizer Classifiers\n",
|
|||
|
"* tfids removes words in pregenerating the vectors by evaluating if this word appears more than 70% often in all articles\n",
|
|||
|
"* an immense naive approach would be to store a set of the over all occuring word in all the texts and for each text determining how often this word occurs.\n",
|
|||
|
"* also testing some min df thresholds as lower bound for regarded occurences"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Generate Vectorizer on Binary Classes"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 18,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"bin_count_vectorizer = CountVectorizer(stop_words='english')\n",
|
|||
|
"bin_count_train = bin_count_vectorizer.fit_transform(bin_X_train)\n",
|
|||
|
"bin_count_test = bin_count_vectorizer.transform(bin_X_test)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 19,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"bin_tfidf_vectorizer = TfidfVectorizer(stop_words='english', max_df=0.7, min_df=0.0005)\n",
|
|||
|
"bin_tfidf_train = bin_tfidf_vectorizer.fit_transform(bin_X_train)\n",
|
|||
|
"bin_tfidf_test = bin_tfidf_vectorizer.transform(bin_X_test)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"a short look on the last 10 tokens for the vectors"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 20,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['zoomed',\n",
|
|||
|
" 'zooming',\n",
|
|||
|
" 'zor',\n",
|
|||
|
" 'zucker',\n",
|
|||
|
" 'zuckerberg',\n",
|
|||
|
" 'zuesse',\n",
|
|||
|
" 'zurich',\n",
|
|||
|
" 'zwick',\n",
|
|||
|
" 'état',\n",
|
|||
|
" 'œthe']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 20,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"bin_tfidf_vectorizer.get_feature_names()[-10:]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 21,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['تنجح', 'حلب', 'عن', 'لم', 'ما', 'محاولات', 'من', 'هذا', 'والمرضى', 'ยงade']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 21,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"bin_count_vectorizer.get_feature_names()[-10:]#[:10]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"### Generate Vectorizer on Multilabel Classes"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 22,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mul_count_vectorizer = CountVectorizer(stop_words='english')\n",
|
|||
|
"mul_count_train = mul_count_vectorizer.fit_transform(mul_X_train)\n",
|
|||
|
"mul_count_test = mul_count_vectorizer.transform(mul_X_test)\n",
|
|||
|
"mul_count_valid = mul_count_vectorizer.transform(mul_X_valid)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 49,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"mul_tfidf_vectorizer = TfidfVectorizer(stop_words='english', max_df=0.7)#, min_df=0.0005)\n",
|
|||
|
"mul_tfidf_train = mul_tfidf_vectorizer.fit_transform(mul_X_train)\n",
|
|||
|
"mul_tfidf_test = mul_tfidf_vectorizer.transform(mul_X_test)\n",
|
|||
|
"mul_tfidf_valid = mul_tfidf_vectorizer.transform(mul_X_valid)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 50,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['zip',\n",
|
|||
|
" 'zippo',\n",
|
|||
|
" 'zombie',\n",
|
|||
|
" 'zombies',\n",
|
|||
|
" 'zone',\n",
|
|||
|
" 'zones',\n",
|
|||
|
" 'zoning',\n",
|
|||
|
" 'zoo',\n",
|
|||
|
" 'zuckerberg',\n",
|
|||
|
" 'zuckerbergs']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 50,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"mul_tfidf_vectorizer.get_feature_names()[-10:]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 51,
|
|||
|
"metadata": {
|
|||
|
"scrolled": true
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"text/plain": [
|
|||
|
"['zip',\n",
|
|||
|
" 'zippo',\n",
|
|||
|
" 'zombie',\n",
|
|||
|
" 'zombies',\n",
|
|||
|
" 'zone',\n",
|
|||
|
" 'zones',\n",
|
|||
|
" 'zoning',\n",
|
|||
|
" 'zoo',\n",
|
|||
|
" 'zuckerberg',\n",
|
|||
|
" 'zuckerbergs']"
|
|||
|
]
|
|||
|
},
|
|||
|
"execution_count": 51,
|
|||
|
"metadata": {},
|
|||
|
"output_type": "execute_result"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"mul_count_vectorizer.get_feature_names()[-10:]#[:10]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Confusion Matrix Code\n",
|
|||
|
"copy paste by distributed notebook"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 32,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"def plot_confusion_matrix(cm, classes,\n",
|
|||
|
" normalize=False,\n",
|
|||
|
" title='Confusion matrix',\n",
|
|||
|
" cmap=plt.cm.Blues):\n",
|
|||
|
" \"\"\"\n",
|
|||
|
" See full source and example: \n",
|
|||
|
" http://scikit-learn.org/stable/auto_examples/model_selection/plot_confusion_matrix.html\n",
|
|||
|
" \n",
|
|||
|
" This function prints and plots the confusion matrix.\n",
|
|||
|
" Normalization can be applied by setting `normalize=True`.\n",
|
|||
|
" \"\"\"\n",
|
|||
|
" #added after jonas hint\n",
|
|||
|
" fig_1,ax_1 = plt.subplots()\n",
|
|||
|
" \n",
|
|||
|
" plt.imshow(cm, interpolation='nearest', cmap=cmap)\n",
|
|||
|
" plt.title(title)\n",
|
|||
|
" plt.colorbar()\n",
|
|||
|
" tick_marks = np.arange(len(classes))\n",
|
|||
|
" plt.xticks(tick_marks, classes, rotation=45)\n",
|
|||
|
" plt.yticks(tick_marks, classes)\n",
|
|||
|
"\n",
|
|||
|
" if normalize:\n",
|
|||
|
" cm = cm.astype('float') / cm.sum(axis=1)[:, np.newaxis]\n",
|
|||
|
" print(\"Normalized confusion matrix\")\n",
|
|||
|
" else:\n",
|
|||
|
" print('Confusion matrix, without normalization')\n",
|
|||
|
"\n",
|
|||
|
" thresh = cm.max() / 2.\n",
|
|||
|
" for i, j in itertools.product(range(cm.shape[0]), range(cm.shape[1])):\n",
|
|||
|
" plt.text(j, i, cm[i, j],\n",
|
|||
|
" horizontalalignment=\"center\",\n",
|
|||
|
" color=\"white\" if cm[i, j] > thresh else \"black\")\n",
|
|||
|
"\n",
|
|||
|
" plt.tight_layout()\n",
|
|||
|
" plt.ylabel('True label')\n",
|
|||
|
" plt.xlabel('Predicted label')"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"# Configurations"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Configuration 1\n",
|
|||
|
"* model a - train - [performance measures][0:4]\n",
|
|||
|
"* model a - test - [performance measures][0:4]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"* model a = MultinomialNB\n",
|
|||
|
" * with tfidf vectorizer* dataset 1\n",
|
|||
|
" * in contrast to the notebook with count vect.\n",
|
|||
|
" * with dataset 1: fake_or_real_news.csv\n",
|
|||
|
" * ** Take care with seeds for example split train test data function**\n",
|
|||
|
" "
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 33,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf = MultinomialNB()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 34,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"accuracy: 0.914\n",
|
|||
|
"Confusion matrix, without normalization\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAA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FmGPfLsIkm1oaGBP/zu\nDHbdY69KhZ1rWS3CUilOrDnwnzGT+fizuYu0bbL2Kjw1Jll055FXJnLADusDsHmP1Xjs1Y8AmPrp\nHGbM+oJtNuoKwMhxU5n0yexWjNwgSQIrd+oEwPx585g/b17Rh4ze+Pcr6LfvQLp2695yxxqlOhXd\n8syJNaden/AJA7ZbF4BBO21Aj64rA/Dqex+z7/brUV8nNlijE1tv2JV1V1+5kqEayQh0vz12pM8W\nG7DLbnvSe7s+APzl92cxYLc+nHPGL5g7N/nl+dHED3jg3rs48rjBlQw51zxibYakBkmjC7aeBfsu\nlvSBpLqCtuMkXZZ+XyfpBknXpkt4jZf0SsGxLilX3Hlx8lVPM3jvzXjs3AF0WnEF5s1fAMBNj47j\ng2mf8+g5Azjv6O15buwU5i9YUOForb6+nmGPPMtTL43lpRdH8sbrr3Hq6b9lxH9Gc+cDT/DJxx9z\n1aV/AeCc03/BL844h/r6+gpHnU+lJNW8J9ZyXryaHRG9mzamyfRAkkcdfBN4tMl+AVcCKwDHR0Sk\n/4h7RMTUMsabK2M//JQDz0/qrhuv1Zl9tkmeBNGwIDjt5i+fRvHAWfvw1kczKxKjLW6VVVdjp513\n5fGHRzD45J8A0KFDBw4+4mj+/teLAHjlpVH8+MRjAPh42jQefWg49fX19B1wQMXizpu8J85iKlEK\n2AN4leQJiEcsYf/FQFfgmIio2aFYt1VWBECCUw/8Gtc++CYAK7Wvp2OH5PfhHluuzfyG4I0PZlQs\nToNpU6fw6YxPAJgzezZ
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.figure.Figure at 0x10b9b55f8>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"clf.fit(bin_tfidf_train, bin_y_train)\n",
|
|||
|
"pred = clf.predict(bin_tfidf_train)\n",
|
|||
|
"score = metrics.accuracy_score(bin_y_train, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(bin_y_train, pred, labels=['FAKE', 'REAL'])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['FAKE', 'REAL'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 35,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"accuracy: 0.872\n",
|
|||
|
"Confusion matrix, without normalization\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVAAAAEmCAYAAAA0k8gFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3XecXFX9//HXe9MoAUJIgyQQSij+\nQAIJCKhIEwgCQaUjNRJBkC+CBRHbV1DUr3SkiRBQKV9pMSDFACJ8aQmEJiUJBFgSSEIJJZSQfH5/\n3LNh2OzOzE5md+7svp8+7mNnzj1z7md25ZNz7rn3XEUEZmbWdg21DsDMrF45gZqZVcgJ1MysQk6g\nZmYVcgI1M6uQE6iZWYWcQK1VkpaX9HdJ8yX97zK0c5Ck26sZW61I+qKkZ2sdh+WDfB1o/ZN0IHAC\nsCHwDjAVOC0i7l3Gdg8GvgNsExEfL3OgOScpgOERMb3WsVh9cA+0zkk6ATgL+BUwEFgT+AMwpgrN\nrwU81xWSZzkkda91DJYzEeGtTjdgFeBdYJ8idXqRJdhZaTsL6JX2bQc0AicCc4DZwOFp3y+Aj4CF\n6RhjgZ8Dfy5oexgQQPf0/jDgebJe8AvAQQXl9xZ8bhvgYWB++rlNwb67gV8C96V2bgf6tfLdmu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ftlkAlLZI0tWAbVrDvbEmvSGooKDtM0nnpdYOk8ZL+lO4KmCnp\niYK2zmmvuGupe7cGRqw3gEsmPs7Wx/6FBR98zPf224JLJj7OZw6/jM99+8+8+sZ7nH7ktgCMv+1J\nXpn7LvedeyC/O2o7Hvj
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.figure.Figure at 0x114164898>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"clf.fit(bin_tfidf_train, bin_y_train)\n",
|
|||
|
"pred = clf.predict(bin_tfidf_test)\n",
|
|||
|
"score = metrics.accuracy_score(bin_y_test, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(bin_y_test, pred, labels=['FAKE', 'REAL'])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['FAKE', 'REAL'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Configuration 2\n",
|
|||
|
"* model b - train - [performance measures]\n",
|
|||
|
"* model b - validation - [performance measures]\n",
|
|||
|
"* model b - test - [performance measures]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 53,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf = MultinomialNB()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 58,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"accuracy: 0.602\n",
|
|||
|
"Confusion matrix, without normalization\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|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A4o/9RTBp06x\netVK8uTN6xYtj4Rrl5PVBw6qamQIQUSyAldUNVxECgL+wF+qekVEbopIFWAb0BmY6KwDM+JNIrb/\ndZVrt0Oj2ELu/eMwn0zpg9q/WFQhta/1HZnK15vrt0MJe6CcuHSLE5duA3Dhxj0uh9x36e5ZIkKa\nNGkACA0NJTQ0FBEhPDycAf16M2zEaJf1HZueVKktPWFhoYSFhYEIP8/8mtff64OXl/XPO3OWrAAs\nmfd/1GvSHL9ceaLYXUGVajXJkDHjQ3pDbt4A4OaN62TPYf1COXLoADWergNA4SJFCf77JBcvnHeZ\nNkf8/PwoV84aladNm5aixYpz5sxpAHr3/IBhI0YTj9VRbsZe1eCsOGtFZDawBSgqIsEiEvEt2Z6H\nJ9VqAXtEZDfwC9BNVSMm5roDXwNHsUbCca5oADPiTXb0aFKEVhVzcfNOGJ2mbgNg5qYTfPVKRbYM\nrktqXx/embmT6DlKS+dJTwpvL05evu1SfeHh4VSvUpG/jh2la7c3qFQ5gMkTP6PpM83x83NtqCM2\nPR2eqcXfJ/6iXefXKF2uEsEnj7Nswa+sXrqQjJkz0+ejMeQrUJiTfx0lLCyULs815VZICJ1e6Ubz\nNh3dpnXIiLF0atOMoYP68kCVeUvXAPBUyVIsWTCPylWqszNoO8Gn/ubsmdNkzZbdbdoATp44we7d\nO6lUOYCFC+aTM1dOSpcp4/zGpCARnlxT1Q6x2F+KwTYXmBtL/UCg5KP0/a8f8YrIOyJyQERmxXK9\ntogsjOlaUjBuyWFqDF3DvB1neKFGPgBqFs3K/tM3qPrRapqP28iQViVI4/vPd2bWtL6M61iGPj/t\necghJzbe3t5s3b6Tw3+
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.figure.Figure at 0x1141259e8>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"clf.fit(mul_tfidf_train, mul_y_train)\n",
|
|||
|
"pred = clf.predict(mul_tfidf_train)\n",
|
|||
|
"\n",
|
|||
|
"#print(pred[:20])\n",
|
|||
|
"\n",
|
|||
|
"score = metrics.accuracy_score(mul_y_train, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(mul_y_train, pred, labels=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 59,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf = MultinomialNB()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 60,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"accuracy: 0.238\n",
|
|||
|
"Confusion matrix, without normalization\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAEmCAYAAAAnRIjxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzs3Xd8FFXXwPHfSUJvAULvTUCQIkhX\nioC9dxABUWyIXbG3R0WfVx57b4io2EVEihQFpBcpioAURXovCZBy3j/uBJeQZEPY3dmF8/WzH3Zn\nZmdONvHsnTN37hVVxRhjTOjF+R2AMcYcqyzBGmNMmFiCNcaYMLEEa4wxYWIJ1hhjwsQSrDHGhIkl\nWBNRIlJ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F2tcow8IvIXtzKTblyFdiwYT0VK1Zi\nw4b1JCWV9y2WT39Zw6e/rAFg0Pknsn5HCn9u3EOPl38BoHb54pzeuIIvsSWWc8ctWSaJZh3PYNVv\nv0Z9gh3x8YeMHzuaz0eORaItocXIYC/R0Y4OE69AXRsYKSL3icgvIjLf+7d+Ntt39ArbC7ztSnjL\n7xGR2d79yY9HIvZOdcsyefmhddbmVUuxdkcKW/YeyOFdkXfm2ecyYvgwAEYMH8ZZ55znWyxlixcE\noHLpIpzVrDLfzF57cJkI3HZWfYZNWR3xuPanJLNv756Dz3+fOYUqtQ/784sqE38cyysv/B9DP/2K\nokWjbZocsRJBNFDVG71uF52BA8DzqpomIl2Bp4FLsrzlbtzVwWkiUhzYJyLdcV0yWuE6iIwUkdO8\n2+wO4d0p0h+gcJmK+Y6
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.figure.Figure at 0x1147ef588>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"clf.fit(mul_tfidf_train, mul_y_train)\n",
|
|||
|
"pred = clf.predict(mul_tfidf_test)\n",
|
|||
|
"score = metrics.accuracy_score(mul_y_test, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(mul_y_test, pred, labels=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf = MultinomialNB()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 76,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"accuracy: 0.231\n",
|
|||
|
"Confusion matrix, without normalization\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAEmCAYAAAAnRIjxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzsnXd4FFUXh9+ThNAChA5JqKEHBSH0\nIioiSFOpigiCIJ8ooqLyoWJXPjuKimABFWmKCkiVIkWkRIrSQ5OEXg2hhCzn+2MmYQlJdkl2k2y4\nL888mbn3zv2dSZazd85toqoYDAaDwfP4ZbcBBoPBkFsxDtZgMBi8hHGwBoPB4CWMgzUYDAYvYRys\nwWAweAnjYA0Gg8FLGAdryFJEJL+IzBKR0yIyPRP19BKRBZ60LbsQkRYisj277TB4HjHjYA2pISL3\nAU8CNYA4YAPwuqquyGS9vYHHgKaqmphpQ3M4IqJAVVWNzm5bDFmPacEarkJEngQ+AN4ASgPlgU+A\nzh6ovgKw43pwru4gIgHZbYPBi6iqOcyRfABFgDNAt3TK5MVywAfs4wMgr53XCogBngKOAAeBB+28\nl4EE4KKt0R94CfjWqe6KgAIB9nVfYDdWK3oP0MspfYXTfU2BtcBp+2dTp7ylwKvASrueBUCJNJ4t\nyf5nnOy/C7gT2AGcAEY4lW8IrAJO2WXHAIF23jL7WeLt5+3hVP+zwCHgm6Q0+55wW6OefR0CHANa\nZfdnwxzXfpgWrCElTYB8wI/plHkOaAzUBepgOZnnnfLLYDnqUCwn+rGIFFXVF7FaxVNVNUhVv0jP\nEBEpCHwItFPVQlhOdEMq5YoBv9hliwPvAb+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lib.figure.Figure at 0x114858fd0>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"clf.fit(mul_tfidf_train, mul_y_train)\n",
|
|||
|
"pred = clf.predict(mul_tfidf_valid)\n",
|
|||
|
"score = metrics.accuracy_score(mul_y_valid, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(mul_y_valid, pred, labels=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Configuration 3 (!no train)\n",
|
|||
|
"* model a - test - dataset2 - [performance measures]\n",
|
|||
|
"* model b - test - dataset1 - [performance measures]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 65,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf = MultinomialNB()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 73,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"0 true\n",
|
|||
|
"1 false\n",
|
|||
|
"2 false\n",
|
|||
|
"3 half-true\n",
|
|||
|
"4 pants-fire\n",
|
|||
|
"5 true\n",
|
|||
|
"6 true\n",
|
|||
|
"7 barely-true\n",
|
|||
|
"8 true\n",
|
|||
|
"9 barely-true\n",
|
|||
|
"10 barely-true\n",
|
|||
|
"11 barely-true\n",
|
|||
|
"12 pants-fire\n",
|
|||
|
"13 false\n",
|
|||
|
"14 half-true\n",
|
|||
|
"15 true\n",
|
|||
|
"16 pants-fire\n",
|
|||
|
"17 half-true\n",
|
|||
|
"18 true\n",
|
|||
|
"19 false\n",
|
|||
|
"20 mostly-true\n",
|
|||
|
"21 half-true\n",
|
|||
|
"22 pants-fire\n",
|
|||
|
"23 mostly-true\n",
|
|||
|
"24 false\n",
|
|||
|
"25 true\n",
|
|||
|
"26 barely-true\n",
|
|||
|
"27 half-true\n",
|
|||
|
"28 true\n",
|
|||
|
"29 mostly-true\n",
|
|||
|
"Name: y, dtype: object\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"#print(type(bin_tfidf_train),type(mul_tfidf_test))\n",
|
|||
|
"\n",
|
|||
|
"tmp_mul_tfidf_test = bin_tfidf_vectorizer.transform(mul_X_test)\n",
|
|||
|
"\n",
|
|||
|
"print(mul_y_test[:5])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 96,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf.fit(bin_tfidf_train, bin_y_train)\n",
|
|||
|
"pred = clf.predict(tmp_mul_tfidf_test)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 97,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"1267\n",
|
|||
|
"['true' 'true' 'true' 'true' 'true' 'true' 'true' 'true' 'true' 'true'\n",
|
|||
|
" 'true' 'true' 'true' 'true' 'true' 'true' 'false' 'true' 'true' 'true'\n",
|
|||
|
" 'true' 'true' 'true' 'false' 'false' 'true' 'false' 'true' 'true' 'false']\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"print(len(pred))\n",
|
|||
|
"pred = np.array(pred, dtype=object)\n",
|
|||
|
"\n",
|
|||
|
"pred[pred == \"FAKE\"] = \"false\"\n",
|
|||
|
"pred[pred == \"REAL\"] = \"true\"\n",
|
|||
|
"\n",
|
|||
|
"print(pred[:30])\n",
|
|||
|
"#pred[pred['FAKE']==false]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 99,
|
|||
|
"metadata": {
|
|||
|
"scrolled": true
|
|||
|
},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"accuracy: 0.169\n",
|
|||
|
"Confusion matrix, without normalization\n"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"data": {
|
|||
|
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAEmCAYAAAAnRIjxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzsnXuc1eP2x9+fmZRSJNeaKd0ole6F\nJCEpJdeIUDiuuZ+Qy49w0HE5jlwP5zg4OpXrQShx3EkXIvdKOd2EkG66TOv3x/Od2k0zs/dMe8/e\nu1nvXt/X7P18n/18P3s3s/bzXc961pKZ4TiO4ySfnHQLcBzH2VpxA+s4jpMi3MA6juOkCDewjuM4\nKcINrOM4TopwA+s4jpMi3MA6FYqk6pJelLRU0lNbMM5ASa8mU1u6kHSgpK/TrcNJPvI4WKc4JJ0M\nXAY0B5YB04GbzezdLRz3VOBCoIuZrdtioRmOJAP2NLNZ6dbiVDw+g3U2Q9JlwF+BW4DdgAbA/cBR\nSRh+D+CbymBcE0FSlXRrcFKImfnhx4YD2AFYDvQvpU81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y\nuSbX+qXzkmYRc2o3sGpdr4jb7/eXLvwO+Cmm6SEze6hov2gy9RZws5k9K+lXM6sdc/4XM9tR0kuE\nv/13o/bXgSvMbFpJGrbqGWwRbgLeMLNjom+rN4t2MLMR0Yd4BDApmumK8KH+rQK1Oo5TIgkne/nJ\nzDqWOpK0DfAMMMrMno2aF0uqG81e6wI/RO3zgdhb03xgYWnjb9U+2CLsABTGwwwuroOkJmY2w8z+\nDEwFmgMTgDOibzkk5cX
|
|||
|
"text/plain": [
|
|||
|
"<matplotlib.figure.Figure at 0x1141d4b38>"
|
|||
|
]
|
|||
|
},
|
|||
|
"metadata": {},
|
|||
|
"output_type": "display_data"
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"score = metrics.accuracy_score(mul_y_test, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(mul_y_test, pred, labels=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true' ])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": 119,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf = MultinomialNB()\n",
|
|||
|
"from sklearn.neural_network import MLPClassifier\n",
|
|||
|
"\n",
|
|||
|
"clf = MLPClassifier()"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [
|
|||
|
{
|
|||
|
"name": "stdout",
|
|||
|
"output_type": "stream",
|
|||
|
"text": [
|
|||
|
"0 true\n",
|
|||
|
"1 false\n",
|
|||
|
"2 false\n",
|
|||
|
"3 half-true\n",
|
|||
|
"4 pants-fire\n",
|
|||
|
"5 true\n",
|
|||
|
"6 true\n",
|
|||
|
"7 barely-true\n",
|
|||
|
"8 true\n",
|
|||
|
"9 barely-true\n",
|
|||
|
"Name: y, dtype: object\n"
|
|||
|
]
|
|||
|
}
|
|||
|
],
|
|||
|
"source": [
|
|||
|
"tmp_bin_tfidf_test = mul_tfidf_vectorizer.transform(bin_X_test)\n",
|
|||
|
"\n",
|
|||
|
"print(mul_y_test[:10])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"clf.fit(mul_tfidf_train, mul_y_train)\n",
|
|||
|
"pred = clf.predict(tmp_bin_tfidf_test)"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"print(pred[:20])\n",
|
|||
|
"\n",
|
|||
|
"bin_y_test = np.array(bin_y_test, dtype=object)\n",
|
|||
|
"\n",
|
|||
|
"bin_y_test[bin_y_test == \"FAKE\"] = \"false\"\n",
|
|||
|
"bin_y_test[bin_y_test == \"REAL\"] = \"true\""
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {},
|
|||
|
"outputs": [],
|
|||
|
"source": [
|
|||
|
"score = metrics.accuracy_score(bin_y_test, pred)\n",
|
|||
|
"print(\"accuracy: %0.3f\" % score)\n",
|
|||
|
"cm = metrics.confusion_matrix(bin_y_test, pred, labels=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])\n",
|
|||
|
"plot_confusion_matrix(cm, classes=['false', 'barely-true' , 'half-true' , 'mostly-true' , 'true'])"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "markdown",
|
|||
|
"metadata": {},
|
|||
|
"source": [
|
|||
|
"## Configuration 4\n",
|
|||
|
"* model c - train - [performance measures][0:4]\n",
|
|||
|
"* model c - test - [performance measures][0:4]"
|
|||
|
]
|
|||
|
},
|
|||
|
{
|
|||
|
"cell_type": "code",
|
|||
|
"execution_count": null,
|
|||
|
"metadata": {
|
|||
|
"collapsed": true
|
|||
|
},
|
|||
|
"outputs": [],
|
|||
|
"source": []
|
|||
|
}
|
|||
|
],
|
|||
|
"metadata": {
|
|||
|
"kernelspec": {
|
|||
|
"display_name": "Python 3",
|
|||
|
"language": "python",
|
|||
|
"name": "python3"
|
|||
|
},
|
|||
|
"language_info": {
|
|||
|
"codemirror_mode": {
|
|||
|
"name": "ipython",
|
|||
|
"version": 3
|
|||
|
},
|
|||
|
"file_extension": ".py",
|
|||
|
"mimetype": "text/x-python",
|
|||
|
"name": "python",
|
|||
|
"nbconvert_exporter": "python",
|
|||
|
"pygments_lexer": "ipython3",
|
|||
|
"version": "3.6.3"
|
|||
|
}
|
|||
|
},
|
|||
|
"nbformat": 4,
|
|||
|
"nbformat_minor": 2
|
|||
|
}
|