nlp-lab/Carsten_Solutions/Task 2 - Carsten Draschner.ipynb

1891 lines
227 KiB
Plaintext
Raw Normal View History

2018-05-13 19:40:03 +02:00
{
"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",
2018-05-15 10:28:16 +02:00
"from sklearn.neural_network import MLPClassifier\n",
2018-05-13 19:40:03 +02:00
"from sklearn import metrics\n",
"import matplotlib.pyplot as plt\n",
"\n",
"#https://github.com/kjam/random_hackery/blob/master/Attempting%20to%20detect%20fake%20news.ipynb"
2018-05-13 19:40:03 +02:00
]
},
{
"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": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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 Hillarys 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 Hillarys 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": [
2018-05-15 10:28:16 +02:00
"store label column with the classification of each text"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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",
2018-05-15 10:28:16 +02:00
"* use seed 4222\n",
"* determine split size: in this case 0.25\n",
"* **take care that these config is the same to get compareable results**"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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",
2018-05-15 10:28:16 +02:00
"* Read in File liar_dataset.zip\n",
"* cause of three file read in each file on its own and assign it to train test vaidation \n",
"\n",
"#### So first train set\n",
"\n",
"* only use the text part and ignore the others\n",
"* it would also be possible to for example to concatiate the other information ito the text part but youll lose the robustness againstother datasets without these coulums and you'll mix up information"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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"
]
},
2018-05-15 10:28:16 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### second dataset: test set"
]
},
2018-05-13 19:40:03 +02:00
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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"
]
},
2018-05-15 10:28:16 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### as third dataset: validation set"
]
},
2018-05-13 19:40:03 +02:00
{
"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",
"{'true', 'pants-fire', 'false', 'barely-true', 'mostly-true', 'half-true'} 10240\n",
2018-05-13 19:40:03 +02:00
"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": "markdown",
"metadata": {},
"source": [
"# Vectorizer Classifiers\n",
2018-05-15 10:28:16 +02:00
"* tfids removes words in pregenerating the vectors by evaluating if this word appears more than 70% often in all articles (tfidf)\n",
2018-05-13 19:40:03 +02:00
"* 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",
2018-05-15 10:28:16 +02:00
"* also testing some min df thresholds as lower bound for regarded occurences of words over all texts ... not easy to predict if this is a good idea"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Generate Vectorizer on Binary Classes"
]
},
2018-05-15 10:28:16 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"generate two different vectorizers"
]
},
2018-05-13 19:40:03 +02:00
{
"cell_type": "code",
"execution_count": 18,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"outputs": [],
"source": [
2018-05-15 10:28:16 +02:00
"#building the vectorspace\n",
2018-05-13 19:40:03 +02:00
"bin_count_vectorizer = CountVectorizer(stop_words='english')\n",
"bin_count_train = bin_count_vectorizer.fit_transform(bin_X_train)\n",
2018-05-15 10:28:16 +02:00
"#transform the other sets into same feature vector as trained on train data \n",
2018-05-13 19:40:03 +02:00
"bin_count_test = bin_count_vectorizer.transform(bin_X_test)"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"outputs": [],
"source": [
2018-05-15 10:28:16 +02:00
"#building the vectorspace\n",
"bin_tfidf_vectorizer = TfidfVectorizer(stop_words='english', max_df=0.7)#, min_df=0.0005)\n",
2018-05-13 19:40:03 +02:00
"bin_tfidf_train = bin_tfidf_vectorizer.fit_transform(bin_X_train)\n",
2018-05-15 10:28:16 +02:00
"#transform the other sets into same feature vector as trained on train data \n",
2018-05-13 19:40:03 +02:00
"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": [
"['تنجح', 'حلب', 'عن', 'لم', 'ما', 'محاولات', 'من', 'هذا', 'والمرضى', 'ยงade']"
2018-05-13 19:40:03 +02:00
]
},
"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": [
2018-05-15 10:28:16 +02:00
"### Generate Vectorizer on Multilabel Classes\n",
"* same again\n",
"* only additional transform for validation set"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"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",
2018-05-15 10:28:16 +02:00
"execution_count": 23,
2018-05-13 19:40:03 +02:00
"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",
2018-05-15 10:28:16 +02:00
"execution_count": 24,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['zip',\n",
" 'zippo',\n",
" 'zombie',\n",
" 'zombies',\n",
" 'zone',\n",
" 'zones',\n",
" 'zoning',\n",
" 'zoo',\n",
" 'zuckerberg',\n",
" 'zuckerbergs']"
]
},
2018-05-15 10:28:16 +02:00
"execution_count": 24,
2018-05-13 19:40:03 +02:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mul_tfidf_vectorizer.get_feature_names()[-10:]"
]
},
{
"cell_type": "code",
2018-05-15 10:28:16 +02:00
"execution_count": 25,
2018-05-13 19:40:03 +02:00
"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']"
]
},
2018-05-15 10:28:16 +02:00
"execution_count": 25,
2018-05-13 19:40:03 +02:00
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"mul_count_vectorizer.get_feature_names()[-10:]#[:10]"
]
},
2018-05-15 10:28:16 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Generate Vectors on merged Sets\n",
"* again the same ..."
]
},
{
"cell_type": "code",
"execution_count": 26,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"concat_count_vectorizer = CountVectorizer(stop_words='english')\n",
"concat_count_train = concat_count_vectorizer.fit_transform(concat_X_train)\n",
"concat_count_test = concat_count_vectorizer.transform(concat_X_test)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"concat_tfidf_vectorizer = TfidfVectorizer(stop_words='english', max_df=0.7)#, min_df=0.0005)\n",
"concat_tfidf_train = concat_tfidf_vectorizer.fit_transform(concat_X_train)\n",
"concat_tfidf_test = concat_tfidf_vectorizer.transform(concat_X_test)"
]
},
{
"cell_type": "code",
"execution_count": 28,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['القادمون',\n",
" 'ایران',\n",
" 'جنگ',\n",
" 'سال',\n",
" 'عربي',\n",
" 'علیه',\n",
" 'مطالعاتی',\n",
" 'مورد',\n",
" 'کدآمایی',\n",
" 'ยงade']"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"concat_tfidf_vectorizer.get_feature_names()[-10:]"
]
},
{
"cell_type": "code",
"execution_count": 29,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['القادمون',\n",
" 'ایران',\n",
" 'جنگ',\n",
" 'سال',\n",
" 'عربي',\n",
" 'علیه',\n",
" 'مطالعاتی',\n",
" 'مورد',\n",
" 'کدآمایی',\n",
" 'ยงade']"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"concat_count_vectorizer.get_feature_names()[-10:]#[:10]"
]
},
2018-05-13 19:40:03 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Confusion Matrix Code\n",
2018-05-15 10:28:16 +02:00
"* copy paste by distributed notebook\n",
"* thx for providing"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
2018-05-15 10:28:16 +02:00
"execution_count": 30,
2018-05-13 19:40:03 +02:00
"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": "markdown",
"metadata": {},
"source": [
"## Dictionary definition for export to rdf in the end"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"example_configuration = {\n",
" \"name\":\"experiment1\",\n",
" \n",
" \"model\":\"generic_model_1_name\",\n",
" \"model-name\":\"deepNN\",\n",
"\n",
"\n",
" \"dataset\":\"X1\",\n",
" \"dataset-name\":\"fake_or_real_news\",\n",
" \"dataset-link\":\"'/Users/Carsten/GitRepos/NLP-LAB/Carsten_Solutions/sets/fact checking/fake_or_real_news.csv'\",\n",
" \n",
" \"measurement-name\":\"measurement_configuration1\",\n",
" \n",
" \"execution-name\":\"execution_configuration1\",\n",
" \n",
" \"precision\":0.33,\n",
" \"recall\":0.73,\n",
" \"accuracy\":0.55\n",
"}"
]
},
2018-05-13 19:40:03 +02:00
{
"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": 32,
2018-05-13 19:40:03 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"clf_model_a = MultinomialNB()"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 33,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.887\n",
2018-05-13 19:40:03 +02:00
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVYAAAEmCAYAAAA5jbhCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xm8VXW5x/HP9xxwBAVkEAVBCacc\ncEJTU0pTnMmcUHHIQkvrds26aA6YWZZeU9Msvc6WaJmKc2o55qyAmIqomCiCiCGzcHjuH2sd2hw5\nZ29g7bPXPvv77rVe7P1ba6/1LLY9/Pazfuu3FBGYmVl26iodgJlZW+PEamaWMSdWM7OMObGamWXM\nidXMLGNOrGZmGXNitWZJWl3S3ZJmSvrTSuznKEl/zTK2SpH0ZUlvVDoOyzd5HGv1k3QkcCqwKTAL\nGAOcHxFPruR+hwHfA3aOiEUrHWjOSQqgf0RMrHQsVt3cY61ykk4FLgF+DvQANgB+CxyUwe77ABNq\nIamWQlK7SsdgVSIivFTpAqwNzAYObWGbVUkS7wfpcgmwarpuEDAZ+CEwDZgCHJ+uOxf4DFiYHuME\nYCRwc8G++wIBtEvfHwe8TdJrfgc4qqD9yYLP7Qw8D8xM/9y5YN2jwHnAU+l+/gp0bebcGuP/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6z6dSvrcoM26M37yTKbP/qyc4VkT3Xr0BKBL124M2nt/Xh37IgD33P5Hnvzb\ng/zskquXJIsH7/oTX9ptT9q1b0+Xrt3YevudeG3cyxWLPY8yejRLxVSixvoVYDzJ82SGLmP9pcA6\nwDGNvdlaNO3T+ez0heR
2018-05-13 19:40:03 +02:00
"text/plain": [
"<matplotlib.figure.Figure at 0x1a1640c550>"
2018-05-13 19:40:03 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"clf_model_a.fit(bin_tfidf_train, bin_y_train)\n",
"pred = clf_model_a.predict(bin_tfidf_train)\n",
2018-05-13 19:40:03 +02:00
"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": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 34,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.826\n",
2018-05-13 19:40:03 +02:00
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVAAAAEmCAYAAAA0k8gFAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xe8FNX9//HX+4IgCIKIIFLEgprY\nEGs0VoxdIcauiAaDGk23xfhNNImJiYmxxkTjV9EU9GuiMWo0xBLLzxILoEYF7CiCWLAA0j6/P+Zc\nsl7v3d277GVnue+nj3nszpmzM2dZ+XDKzDmKCMzMrPUaal0AM7N65QBqZlYhB1Az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v\nYfo783jl7Y/YfFBPnnzlvVoWt11ZbY2+rLZGXwC6rNKN/uuuzzuzWq64TH9xCptuuyMAPXr1pmv3\nHrzwzCSGbLrFcilvPVBDdQJoREwEmusnHd5M3gBOas35/U9eDgVwzditufmb23PotlmXzODeq7D1\nOqtx49c/xx9P3JZNB/YAoG+PlZnx3vyln33zvfn07bFyLYptwKzXX+Pl555myKbZPdh3jL+abx88\nnMt+8C0+fD/7R23wBhvz6D13snjRIma+/iov/mcyb88s2tXW7lTrRvq21mY1UEmLgacKkkZGxMvp\n2EXAQcDAiFiS0o4BtoqIkyU1AFcDi4ExwEvAB2kf4L6I+Hpblb3WDr30YWa9/zG9unVi3NitefGt\nD+nYQazaZSUOuvghNhvYg4tHDWXXn/yr+WHDcPu9FubN/YhfnHIcx5z6Q7p2686eh4zmoLHfQhLj\nL/s54355Died8yt2G3k
2018-05-13 19:40:03 +02:00
"text/plain": [
"<matplotlib.figure.Figure at 0x1a162f7b70>"
2018-05-13 19:40:03 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#clf_model_a.fit(bin_tfidf_train, bin_y_train)\n",
"pred = clf_model_a.predict(bin_tfidf_test)\n",
2018-05-13 19:40:03 +02:00
"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'])\n",
"\n",
"precision = cm[1,1]/(cm[1,1]+cm[0,1])\n",
"recall = cm[1,1]/(cm[1,1]+cm[1,0])"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"configuration_1 = {\n",
" \"name\":\"configuration1\",\n",
" \n",
" \"model\":\"model_a\",\n",
" \"model-name\":\"multinomialNB\",\n",
"\n",
"\n",
" \"dataset\":\"X1\",\n",
" \"dataset-name\":\"fake_or_real_news\",\n",
" \"dataset-link\":\"unknown\",\n",
" \n",
" \"measurement-name\":\"measurement_config1\",\n",
" \n",
" \"execution-name\":\"execution_config1\",\n",
" \n",
" \"precision\":precision,\n",
" \"recall\":recall,\n",
" \"accuracy\":score\n",
"}"
2018-05-13 19:40:03 +02:00
]
},
{
"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": 36,
2018-05-13 19:40:03 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"clf_model_b = MultinomialNB()"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 37,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.602\n",
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAV4AAAEmCAYAAAAqWvi2AAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzsnXd8VMXXh5+TBKL0DqG3UKTX0KU3\n4QcISFMsKIJd6UVA6UhRaSqKCiLiKyq99y4JXToCEnqHUJNw3j/uTdyEJBtCdpPVefzMJ/eeO3fm\nu7t4dvbM3DmiqhgMBoPBfXgltQCDwWD4r2Ecr8FgMLgZ43gNBoPBzRjHazAYDG7GOF6DwWBwM8bx\nGgwGg5sxjtfgVkTkSRFZICLXReT/HqOdTiKyPDG1JRUiUlNEDiW1DoP7ELOO1xATItIR+AAoBtwE\ndgHDVXXjY7b7AvA2UE1Vwx5baDJHRBTwV9WjSa3FkHwwI17DQ4jIB8CnwAggO5AXmAK0SITm8wGH\n/wtONz6IiE9SazAkAapqiimRBUgPhABt46jji+WYz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lLCyULs815VZICJ1e6Ubz\nNh3dpnXIiLF0atOMoYP68kCVeUvXAPBUyVIsWTCPylWqszNoO8Gn/ubsmdNkzZbdbdoATp44we7d\nO6lUOYCFC+aTM1dOSpcp4/zGpCARnlxT1Q6x2F+KwTYXmBtL/UCg5KP0/a8f8YrIOyJyQERmxXK9\ntogsjOlaUjBuyWFqDF3DvB1neKFGPgBqFs3K/tM3qPrRapqP28iQViVI4/vPd2bWtL6M61iGPj/t\necghJzbe3t5s3b6Tw3+
"text/plain": [
"<matplotlib.figure.Figure at 0x1a14d84a20>"
2018-05-13 19:40:03 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"clf_model_b.fit(mul_tfidf_train, mul_y_train)\n",
"pred = clf_model_b.predict(mul_tfidf_train)\n",
2018-05-13 19:40:03 +02:00
"\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": 38,
2018-05-13 19:40:03 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#clf = MultinomialNB()"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 39,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.238\n",
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAEmCAYAAAAnRIjxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdG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ND0gw27Y74GKyIDcXPVz1PV\nw6Y+FpFOwN2qem6kY8tNQpzQumZp3p/59yHLO9Ure1jSNbBiw25eHb+MT25tz979afz2z07S05U7\nh83jycubcMfZ9Rm3cAOpaf7MonzPm1+QWK4Cu7Zt4cXbelGxRh3qNW/tSyxH4oX/PkNCQgKXXN7D\n71D+lccSQDQ45hMscDNwltc5OGa0rJ7In1uS2ZHy7wWZOIF2tcow8IvIXtzKTblyFdiwYT0VK1Zi\nw4b1JCWV9y2WT39Zw6e/rAFg0Pknsn5HCn9u3EOPl38BoHb54pzeuIIvsSWWc8ctWSaJZh3PYNVv\nv0Z9gh3x8YeMHzuaz0eORaItocXIYC/R0Y4OE69AXRsYKSL3icgvIjLf+7d+Ntt39ArbC7ztSnjL\n7xGR2d79yY9HIvZOdcsyefmhddbmVUuxdkcKW/YeyOFdkXfm2ecyYvgwAEYMH8ZZ55znWyxlixcE\noHLpIpzVrDLfzF57cJkI3HZWfYZNWR3xuPanJLNv756Dz3+fOYUqtQ/784sqE38cyysv/B9DP/2K\nokWjbZocsRJBNFDVG71uF52BA8DzqpomIl2Bp4FLsrzlbtzVwWkiUhzYJyLdcV0yWuE6iIwUkdO8\n2+wO4d0p0h+gcJmK+Y6
"text/plain": [
"<matplotlib.figure.Figure at 0x1a162ee240>"
2018-05-13 19:40:03 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#clf.fit(mul_tfidf_train, mul_y_train)\n",
"pred = clf_model_b.predict(mul_tfidf_test)\n",
2018-05-13 19:40:03 +02:00
"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": 40,
2018-05-13 19:40:03 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#clf_model_b = MultinomialNB()"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 41,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.231\n",
"Confusion matrix, without normalization\n"
]
},
{
"data": {
2018-05-15 10:28:16 +02:00
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAEmCAYAAAAnRIjxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzs3Xd8FNUWwPHfSUIVhEAIHeldQUCU\nakdQivhAlCJiQRTbU1RUxIIFnr2giA0EVCyoiIgigggiHUR6FVB6kRBqyHl/3AkuIY2Q3dmF8/Wz\nn+zOzM6cbOTsnXPv3BFVxRhjTM6L8jsAY4w5VVmCNcaYILEEa4wxQWIJ1hhjgsQSrDHGBIklWGOM\nCRJLsCakRCSfiHwjIv+IyGcnsZ8uIvJDTsbmFxFpJiLL/Y7D5DyxcbAmLSLSGbgPqA4kAAuAZ1R1\n2knutxtwF9BYVZNOOtAwJyIKVFHVVX7HYkLPWrDmOCJyH/AK8CxQHCgHvAm0y4HdnwWsOB2Sa1aI\nSIzfMZggUlV72OPoAygE7AU6ZrBNHlwC/tt7vALk8dZdBGwE7ge2ApuAHt66J4FDwGHvGDcDTwAj\nA/ZdHlAgxnt9I7AG14peC3QJWD4t4H2NgdnAP97PxgHrpgADgOnefn4A4tL53VLifzAg/quBK4EV\nwE7gkYDtGwIzgN3etm8Aub11U73fJdH7fTsF7P8hYDMwImWZ955K3jHqea9LAduBi/z+f8MeJ/6w\nFqxJrRGQF/gyg20eBS4A6gJ1cEmmX8D6ErhEXRqXRAeLSKyqPo5rFY9W1QKq+l5GgYjIGcBrQ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
2018-05-13 19:40:03 +02:00
"text/plain": [
"<matplotlib.figure.Figure at 0x1a16437780>"
2018-05-13 19:40:03 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#clf_model_b.fit(mul_tfidf_train, mul_y_train)\n",
"pred = clf_model_b.predict(mul_tfidf_valid)\n",
2018-05-13 19:40:03 +02:00
"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": "code",
"execution_count": 42,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"precision = cm[1,1]/(cm[1,1]+cm[0,1])\n",
"recall = cm[1,1]/(cm[1,1]+cm[1,0])"
]
},
{
"cell_type": "code",
"execution_count": 43,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"configuration_2 = {\n",
" \"name\":\"configuration2\",\n",
" \n",
" \"model\":\"model_a\",\n",
" \"model-name\":\"multinomialNB\",\n",
"\n",
"\n",
" \"dataset\":\"X2\",\n",
" \"dataset-name\":\"liar\",\n",
" \"dataset-link\":\"unknown\",\n",
" \n",
" \"measurement-name\":\"measurement_config2\",\n",
" \n",
" \"execution-name\":\"execution_config2\",\n",
" \n",
" \"precision\":precision,\n",
" \"recall\":recall,\n",
" \"accuracy\":score\n",
"}"
]
},
2018-05-13 19:40:03 +02:00
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuration 3\n",
"**In contrast to the discussed true false FAKE REAL bin class approch, I just want to see the expected horible results :)**\n",
2018-05-13 19:40:03 +02:00
"* model a - test - dataset2 - [performance measures]\n",
"* model b - test - dataset1 - [performance measures]"
]
},
{
"cell_type": "code",
"execution_count": 44,
2018-05-13 19:40:03 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"clf_tmp = MultinomialNB()"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 45,
2018-05-13 19:40:03 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
2018-05-15 10:28:16 +02:00
"0 true\n",
"1 false\n",
"2 false\n",
"3 half-true\n",
"4 pants-fire\n",
2018-05-13 19:40:03 +02:00
"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": 46,
2018-05-13 19:40:03 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"clf_tmp.fit(bin_tfidf_train, bin_y_train)\n",
"pred = clf_tmp.predict(tmp_mul_tfidf_test)"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 47,
2018-05-13 19:40:03 +02:00
"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' 'true' 'true' 'true' 'false']\n"
2018-05-13 19:40:03 +02:00
]
}
],
"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": 48,
2018-05-13 19:40:03 +02:00
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.170\n",
2018-05-13 19:40:03 +02:00
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw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PXr2TmlM+Ty2kj1wcVe+nfsro17+rMRj35r6E632qE31apXJqiQObpXN\n1z/9Wg5RFkUZUyLYqnsRmNnZkroBhwJrgDvMbJ2kw4EbgeMKvGUocJ6ZfSipBrBK0pFAU6AjoYPI\nq5IOMbP3Cl5P0hBgCED9mDpbaSxa+DOXXXgm6/PWs379err3OZZDj+jOwN6Hs3zZMsyMZi335ppb\n7y7T+ROlcuXK3HX3PfTqcRR5eXmcMvg0WrRsmdKY8nlsxTugxa4M6tqc6bMX88k/BgIw4rGPqFYl\nizvP6ULtHarz0sjefPHDInpfPYaly1cz6uXP+OD/+mMG4yfPYdykOeUa82bSpARQEhVWE9qaSJoD\n7AtUB0YRkqUBVcysmaQuwFAz6ylpGNAXeAp4yczmSbodOB7Iv71aA7jJzB4u7rp7t2lnviaXK0/p\nvCbX+t9/SlhGrFSrgVU76LISj1s19oIpZrZvoq5bFlt1C7aA64B3zKyvpIbAuwUPMLObJY0FjgY+\niVq6IiTUf5ZjrM65ImXOZC/pUagoHzsA+f1hBhd2gKTGZjbdzG4BJgPNgPHAaVHJAEnZklJc4Xeu\ngvMabNq5FXhM0iXAf4s45mJJhwJ5wFfAm2a2WlJz4OOoO81y4EQgPRehd64iyJAa7FafYM2sYfR0\nMbBnzK6ro/3vEpULzOyCIs5xN5Dau0rOucCX7XbOueRJl4EjJfEE65zLKGG+bU+wzjmXeBKq5AnW\nOeeSIlNasOnRl8E550pBUomPOM6xm6R3osmgZki6KNq+k6S3JM2M/twx2i5JoyTNiobNlzitmCdY\n51xmEaiSSnzEYR3wNzN
2018-05-13 19:40:03 +02:00
"text/plain": [
"<matplotlib.figure.Figure at 0x1a164043c8>"
2018-05-13 19:40:03 +02:00
]
},
"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": 49,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"outputs": [],
"source": [
"clf_tmp = MultinomialNB()\n",
2018-05-15 10:28:16 +02:00
"#from sklearn.neural_network import MLPClassifier\n",
2018-05-13 19:40:03 +02:00
"\n",
2018-05-15 10:28:16 +02:00
"#clf = MLPClassifier(hidden_layer_sizes=(40,20))"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 50,
2018-05-13 19:40:03 +02:00
"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": 51,
"metadata": {
"collapsed": true
},
2018-05-13 19:40:03 +02:00
"outputs": [],
"source": [
"clf_tmp.fit(mul_tfidf_train, mul_y_train)\n",
"pred = clf_tmp.predict(tmp_bin_tfidf_test)"
2018-05-13 19:40:03 +02:00
]
},
{
"cell_type": "code",
"execution_count": 52,
2018-05-13 19:40:03 +02:00
"metadata": {},
2018-05-15 10:28:16 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['half-true' 'false' 'false' 'half-true' 'half-true' 'barely-true' 'false'\n",
" 'mostly-true' 'half-true' 'false' 'half-true' 'half-true' 'false' 'false'\n",
" 'false' 'half-true' 'half-true' 'half-true' 'false' 'true']\n"
]
}
],
2018-05-13 19:40:03 +02:00
"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": 53,
2018-05-13 19:40:03 +02:00
"metadata": {},
2018-05-15 10:28:16 +02:00
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.220\n",
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVgAAAEmCAYAAAAnRIjxAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzsnXeYVFXSh9/fzACCIEFEJShJRWUF\nBXNCREVFMWFCBXNEXcMa1uy64rrqZ17jmhNGVDDrohgAERExgIIKIgoKAhKH+v44Z6AZZ7p7hu7p\nbqjX5z7ce8+551S3UF23Tp0qmRmO4zhO5inKtQCO4zirKq5gHcdxsoQrWMdxnCzhCtZxHCdLuIJ1\nHMfJEq5gHcdxsoQrWKdGkVRX0ouSZksatBLj9JX0WiZlyxWSdpb0Va7lcDKPPA7WqQhJRwLnAB2A\nOcAY4Boze28lxz0aGADsYGZLVlrQPEeSARuZ2cRcy+LUPG7BOn9C0jnA/wH/BNYFNgDuAHpnYPgN\nga9XB+WaDpJKci2Dk0XMzA8/lh1AQ2Au0CdJnzoEBfxjPP4PqBPbugFTgHOBn4FpwLGx7UpgEbA4\nznE8cAXwSMLYrQEDSuJ1f+BbghU9CeibcP+9hOd2AEYCs+OfOyS0vQNcDQyP47wGNK3ks5XJ/7cE\n+Q8A9gG+Bn4FLk7ovw3wATAr9r0NqB3bhsXPMi9+3sMSxr8A+Al4uOxefKZdnGOreN0cmAF0y/Xf\nDT+qfrgF65Rne2AN4Lkkff4ObAd0BjoRlMwlCe3rERR1C4ISvV1SYzO7nGAVP2lm9c3svmSCSFoT\n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.Figure at 0x1a15546a90>"
2018-05-15 10:28:16 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
2018-05-13 19:40:03 +02:00
"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": "markdown",
"metadata": {},
"source": [
"As expected not these fancy results -.- "
]
2018-05-13 19:40:03 +02:00
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Configuration 4\n",
"* model c - train - [performance measures][0:4]\n",
"* model c - test - [performance measures][0:4]"
]
},
2018-05-15 10:28:16 +02:00
{
"cell_type": "code",
"execution_count": 54,
2018-05-15 10:28:16 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"clf_model_c = MultinomialNB()"
2018-05-15 10:28:16 +02:00
]
},
{
"cell_type": "code",
"execution_count": 55,
2018-05-15 10:28:16 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.860\n",
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVYAAAEmCAYAAAA5jbhCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMS4wLCBo\ndHRwOi8vbWF0cGxvdGxpYi5vcmcvpW3flQAAIABJREFUeJzt3Xm8FXX9x/HX+wICiooIKosIIqJG\ngkq4lqaluKWW+nPLJfelNJcktdwyzcyKXEpzwSWVyoXcyX1DWUQRCQERQVBABFERAT+/P2YuHvAu\n58Lce+ae+372mMc95zvfmfkOxNvv/c7MdxQRmJlZdipK3QAzs3LjYDUzy5iD1cwsYw5WM7OMO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atuefq49lx6x788Ptbsfvxf652\nm4P22Ib7nxjDl19+9dqd6R/Mo///XU7HDmsz5Orjue+/rzJr7oKGOAUr8Nlnn/G7yy/jwUce/9q6\nZDL65eW959XQGkNvtBgNNRTQFjhlxcLa3s3dlMz/ZCHPjpzIzv02ZeMNOzBu6IX876GLWb1VC954\n4MLl6h64xzYMeXRklfuZOXs+b05+nx237tEQzbYVvD15MlPfmUL/bfrQa5NuvDd9Otv335r333+f\nzp27MH36Vy/7fO+96XTs1KmErc2nchgKaKhgvQLoIWmMpBGSnpL0D2CspG6S3qisKOlsSReln3tI\nelTSKEnPSdqsgdrbINqv02bZBapWLVuw67a9eHX8NLp//zw22/tCNtv7Qj77fDG997t42TY9N1qP\nddZaneGvTVlW1nm9trR
"text/plain": [
"<matplotlib.figure.Figure at 0x1a155caf60>"
2018-05-15 10:28:16 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"clf_model_c.fit(concat_tfidf_train, concat_y_train)\n",
"pred = clf_model_c.predict(concat_tfidf_train)\n",
2018-05-15 10:28:16 +02:00
"score = metrics.accuracy_score(concat_y_train, pred)\n",
"print(\"accuracy: %0.3f\" % score)\n",
"cm = metrics.confusion_matrix(concat_y_train, pred, labels=['true', 'false'])\n",
"plot_confusion_matrix(cm, classes=['true', 'false'])"
]
},
{
"cell_type": "code",
"execution_count": 56,
2018-05-15 10:28:16 +02:00
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#clf = MultinomialNB()"
2018-05-15 10:28:16 +02:00
]
},
{
"cell_type": "code",
"execution_count": 57,
2018-05-15 10:28:16 +02:00
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"accuracy: 0.749\n",
"Confusion matrix, without normalization\n"
]
},
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAVYAAAEmCAYAAAA5jbhCAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcm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n1o2Pn7yUEX89hzOufJCIAKBH1w68dv9v+Oixi/nfO55mwqQZJau/wS033cCmG67PsUcfxbRp00pd\nnUZFFSpqybMGCVZJHSSd0BDHKmc7bbkOb34wntV3PpfND7yMa87ej3bLJq2f8V9PZ7MDLqNP/ws5\nZK/N6JKGsTW8Y449nnc/GMuwkaPptuKKnH3m6aWuUqNRbGvVLdZEB+BHwSqpWQMdv1GZOGUW3Tq3\nB6Bb5/ZMmjoLgEP33oKHnn0DgI8/n8ynX0yhd8+ui3x2wqQZvDv2K7baaI2GrbQt1LVrV5o1a0ZF\nRQVHDTyGESNeK3WVGhUHa/EuB9aQNFrScEnPSfo/4C1JPSW9XVlQ0hmSLkhfryHpcUkjJf1b0toN\nVN+SeuSFtzhkr80BOGSvzXn4+TcB+PyrafTbrDcAXTq2Y62eXfnki8l079KBVi1bANChXWt+0nd1\nPvx0Ymkqb0yYMGHh64f++Q/WXa9PDaWtqnII1oYax3o20Cci+krqBzySvv9EUs8aPncrcFxEfCRp\nc+Am4KdVC0kaBAwCoEXbbGtez4ZcdgTbbNyLzh3aMubxi7n4lke56vanuPuKozh8wE/4fMI0Dv71\nYAAuv+1xbr3wEIY/cA4SnHvdQ0yZPpufbr42l5+2D0EgxLV3PsM7Y74s8Zk1DYcdchD/fuF5Jk+e\nzBo9e/Db313Iiy88z5t
"text/plain": [
"<matplotlib.figure.Figure at 0x1a16435278>"
2018-05-15 10:28:16 +02:00
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"#clf.fit(concat_tfidf_train, concat_y_train)\n",
"pred = clf_model_c.predict(concat_tfidf_test)\n",
2018-05-15 10:28:16 +02:00
"score = metrics.accuracy_score(concat_y_test, pred)\n",
"print(\"accuracy: %0.3f\" % score)\n",
"cm = metrics.confusion_matrix(concat_y_test, pred, labels=['true', 'false'])\n",
"plot_confusion_matrix(cm, classes=['true', 'false'])"
]
},
{
"cell_type": "code",
"execution_count": 58,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"precision = cm[1,1]/(cm[1,1]+cm[0,1])\n",
"recall = cm[1,1]/(cm[1,1]+cm[1,0])"
]
},
{
"cell_type": "code",
"execution_count": 59,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"configuration_4 = {\n",
" \"name\":\"configuration4\",\n",
" \n",
" \"model\":\"model_c\",\n",
" \"model-name\":\"multinomialNB\",\n",
"\n",
"\n",
" \"dataset\":\"X3\",\n",
" \"dataset-name\":\"concat\",\n",
" \"dataset-link\":\"unknown\",\n",
" \n",
" \"measurement-name\":\"measurement_config4\",\n",
" \n",
" \"execution-name\":\"execution_config4\",\n",
" \n",
" \"precision\":precision,\n",
" \"recall\":recall,\n",
" \"accuracy\":score\n",
"}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Exporting results as RDF data"
]
},
{
"cell_type": "code",
"execution_count": 60,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"from rdflib import Namespace, Graph, Literal\n",
"from rdflib.namespace import FOAF, OWL, XSD, RDFS, DCTERMS, DOAP, DC, RDF"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": 61,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"prov = Namespace('http://www.w3.org/ns/prov#')\n",
"dcat = Namespace('http://www.w3.org/ns/dcat#')\n",
"mexalgo = Namespace('http://mex.aksw.org/mex-algo#')\n",
"mexperf = Namespace('http://mex.aksw.org/mex-perf#')\n",
"mexcore = Namespace('http://mex.aksw.org/mex-core#')\n",
"this = Namespace('http://mex.aksw.org/examples/')"
]
},
{
"cell_type": "code",
"execution_count": 62,
"metadata": {},
"outputs": [],
"source": [
"example_configuration = {\n",
" \"name\":\"experiment1\",\n",
" \n",
" \"model\":\"generic_model_1_name\",\n",
" \"model-name\":\"deepNN\",\n",
"\n",
"\n",
" \"dataset\":\"X1\",\n",
" \"dataset-name\":\"Liar\",\n",
" \"dataset-link\":\"google.com\",\n",
" \n",
" \"measurement-name\":\"generic_measurement_hub\",\n",
" \n",
" \"execution-name\":\"genereric_execution_name\",\n",
" \n",
" \"precision\":0.33,\n",
" \"recall\":0.73,\n",
" \"accuracy\":0.55\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 63,
"metadata": {},
"outputs": [],
"source": [
"def experiment_root_graph(root_node_name):\n",
" g = Graph()\n",
" g.add((this[root_node_name],RDF.type, mexcore.Experiment))\n",
" g.add((this[root_node_name],RDF.type, mexcore.ApplicationContext))\n",
" g.add((this[root_node_name],RDFS.label, Literal('2719095')))\n",
" g.add((this[root_node_name],DCTERMS.date, Literal('2018-05-22',datatype=XSD.date)))\n",
" g.add((this[root_node_name],FOAF.givenName, Literal('Carsten')))\n",
" g.add((this[root_node_name],FOAF.mbox, Literal('carsten.draschner@gmail.com')))\n",
" return g ,this[root_node_name]\n"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'rdflib.term.URIRef'>\n"
]
}
],
"source": [
"g, r = experiment_root_graph(\"first_test\")\n",
"print(type(r))"
]
},
{
"cell_type": "code",
"execution_count": 67,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"#extend a rdf graph with a configuration\n",
"def experiment_to_rdf(graph, experiment, root_node):\n",
" \n",
" g.add((this[experiment[\"name\"]],RDF.type,mexcore.ExperimentConfiguration))\n",
" g.add((this[experiment[\"name\"]],prov.used, this[experiment[\"model\"]]))\n",
" g.add((this[experiment[\"name\"]],prov.wasStartedBy, root_node))\n",
" \n",
" #dataset information\n",
" g.add((this[experiment[\"dataset\"]],RDF.type,mexcore.Dataset))\n",
" g.add((this.dataset2,RDFS.label,Literal(experiment[\"dataset-name\"])))\n",
" g.add((this.dataset2,DCTERMS.landingPage,Literal(experiment[\"dataset-link\"])))\n",
" \n",
" #model description\n",
" g.add((this[experiment[\"model\"]],RDF.type,mexalgo.Algorithm))\n",
" g.add((this[experiment[\"model\"]],RDFS.label,Literal(experiment[\"model-name\"])))\n",
" g.add((this[experiment[\"model\"]],DCTERMS.identifier,Literal(experiment[\"model-name\"])))\n",
" ###g.add((this.model1,mexalgo.hasHyperParameter,this.hyerparameter1))\n",
" \n",
" #execution\n",
" g.add((this[experiment[\"execution-name\"]],RDF.type,mexcore.ExecutionOverall))\n",
" g.add((this[experiment[\"execution-name\"]],prov.generated,this[experiment[\"measurement-name\"]]))\n",
" g.add((this[experiment[\"execution-name\"]],prov.used,this.test))\n",
" g.add((this[experiment[\"execution-name\"]],prov.used,this[experiment[\"model\"]]))\n",
" \n",
" #test\n",
" g.add((this.test,RDF.type,mexcore.Test))\n",
" g.add((this.test,RDFS.label,Literal('Test')))\n",
" \n",
" #evaluation information\n",
" g.add((this[experiment[\"measurement-name\"]],RDF.type,mexcore.PerformanceMeasure))\n",
" g.add((this[experiment[\"measurement-name\"]],mexperf.precision,Literal(experiment[\"precision\"],datatype=XSD.float)))\n",
" g.add((this[experiment[\"measurement-name\"]],mexperf.recall,Literal(experiment[\"recall\"],datatype=XSD.float)))\n",
" g.add((this[experiment[\"measurement-name\"]],mexperf.accuracy,Literal(experiment[\"accuracy\"],datatype=XSD.float)))\n",
" g.add((this[experiment[\"measurement-name\"]],prov.wasGeneratedBy,this[experiment[\"execution-name\"]]))\n"
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"experiment_to_rdf(g,configuration_1,r)\n",
"experiment_to_rdf(g,configuration_2,r)\n",
"experiment_to_rdf(g,configuration_4,r)"
]
},
{
"cell_type": "code",
"execution_count": 69,
"metadata": {},
"outputs": [],
"source": [
"with open('task2_metadata.ttl','wb') as f:\n",
" f.write(g.serialize(format='turtle'))"
]
},
2018-05-13 19:40:03 +02:00
{
"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
}