<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Utku Arık on Medium]]></title>
        <description><![CDATA[Stories by Utku Arık on Medium]]></description>
        <link>https://medium.com/@utkuarik?source=rss-d2faa75732bd------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*SVy4TDto9WF3FnakgoqKKQ.png</url>
            <title>Stories by Utku Arık on Medium</title>
            <link>https://medium.com/@utkuarik?source=rss-d2faa75732bd------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 03 Dec 2026 21:16:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@utkuarik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Machine Learning Web App with Streamlit]]></title>
            <link>https://medium.com/analytics-vidhya/machine-learning-web-app-with-streamlit-7864e04c1fbf?source=rss-d2faa75732bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/7864e04c1fbf</guid>
            <category><![CDATA[titanic]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[data-science]]></category>
            <category><![CDATA[streamlit]]></category>
            <dc:creator><![CDATA[Utku Arık]]></dc:creator>
            <pubDate>Tue, 28 Apr 2020 21:12:27 GMT</pubDate>
            <atom:updated>2020-04-30T16:54:45.893Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Lha4cTvr0jQBRrLt" /><figcaption>Photo by <a href="https://unsplash.com/@ikukevk?utm_source=medium&amp;utm_medium=referral">Kevin Ku</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Streamlit is an open-source app framework for Machine Learning and Data Science. In this article, we will use its visual capabilities to convert our machine learning project to a web application.You can reach official site and documentation via the link :</p><p><a href="https://www.streamlit.io/">Streamlit * The fastest way to build and share data apps</a></p><h4><strong>1. File Input:</strong></h4><p>In order to create file uploader model to import the user data, we will use the pre defined file uploader gadget of Streamlit.</p><p>First of all we need to install streamlit into our pyhton environment:</p><pre>pip install streamlit</pre><p>Now, we can start using streamlit by importing:</p><pre>import streamlit as st</pre><p>As a sample input file, we will use famous titanic dataset. You can reach the dataset from this link:</p><p><a href="https://www.kaggle.com/c/titanic/data">Titanic - Machine Learning from Disaster</a></p><p>By using the below code we can read the data from user:</p><pre><strong>def file_selector(self):<br>   </strong>file = st.sidebar.file_uploader(&quot;Choose a CSV file&quot;, type=&quot;csv&quot;)<br>   if file is not None:<br>      data = pd.read_csv(file)<br>      return data<br>   else:<br>      st.text(&quot;Please upload a csv file&quot;)</pre><blockquote>When adding streamlit gadgets, using “<strong>st.sidebar” </strong>before the widget call will append your widget in the sidebar which is on the left part of the screen. However, using only the <strong>“st” </strong>will add the widget on main panel.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*22RlkEvmcJvexOU24Q6Gag.png" /><figcaption>File Uploader Widget of Streamlit</figcaption></figure><p><strong><em>Choose the required columns from data:</em></strong></p><p>In here, “<strong><em>multiselect</em></strong>” widget gives us multiple selection opportunity.</p><pre><strong>def set_features(self):</strong><br>   self.features = st.multiselect(‘Please choose the features including target variable that go into the model’, self.data.columns )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*M8mprWZjRA3oQH6LjEnJYw.png" /><figcaption>Multiselect selection widget</figcaption></figure><h4><strong>2. Data Preparation:</strong></h4><pre><strong>def prepare_data(self, split_data, train_test):</strong><br>   # Reduce data size<br>   data = self.data[self.features]<br>   data = data.sample(frac = round(split_data/100,2))</pre><p><strong><em>Impute “nan”s with mean for numerics features and most frequent for categoricals:</em></strong></p><pre>   # Impute nans with mean for numeris and most frequent for categoricals<br>   cat_imp = SimpleImputer(strategy=&quot;most_frequent&quot;)<br>   if len(data.loc[:,data.dtypes == &#39;object&#39;].columns) != 0:<br>      data.loc[:,data.dtypes == &#39;object&#39;] = cat_imp.fit_transform(data.loc[:,data.dtypes == &#39;object&#39;])<br>      imp = SimpleImputer(missing_values = np.nan, strategy=&quot;mean&quot;)<br>      data.loc[:,data.dtypes != &#39;object&#39;] =      imp.fit_transform(data.loc[:,data.dtypes != &#39;object&#39;])</pre><p><strong><em>One hot encoding for categorical variables:</em></strong></p><pre>   # One hot encoding for categorical variables<br>      cats = data.dtypes == &#39;object&#39;<br>      le = LabelEncoder()<br>      for x in data.columns[cats]:<br>         data.loc[:,x] = le.fit_transform(data[x])<br>         onehotencoder = OneHotEncoder()      <br>         data.loc[:,~cats].join(pd.DataFrame(data=onehotencoder.<br>         fit_transform (data.loc[:,cats]).toarray(), columns= <br>         onehotencoder.get_feature_names()))</pre><p><strong><em>Set the target column:</em></strong></p><p>We will set the target column by user choice by adding <strong><em>“selectbox”</em></strong> widget on sidebar panel like below:</p><pre># Set target column<br>target_options = data.columns<br>self.chosen_target = st.sidebar.selectbox(&quot;Please choose target column&quot;, (target_options))</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*QFJYBjgEzTBV-0ceHY92xA.png" /><figcaption>Selectbox widget for target selection</figcaption></figure><p><strong><em>Standardize the feature data:</em></strong></p><pre># Standardize the feature data<br>X = data.loc[:, data.columns != self.chosen_target]<br>scaler = MinMaxScaler(feature_range=(0,1))<br>scaler.fit(X)<br>X = pd.DataFrame(scaler.transform(X))<br>X.columns = data.loc[:, data.columns != self.chosen_target].columns<br>y = data[self.chosen_target]</pre><p><strong><em>Train test split:</em></strong></p><pre># Train test split<br>try:<br>   self.X_train, self.X_test, self.y_train, self.y_test =     train_test_split(X, y, test_size=(1 - train_test/100), random_state=42)</pre><pre>except:<br>   st.markdown(&#39;&lt;span style=&quot;color:red&quot;&gt;With this amount of data and   split size the train data will have no records, &lt;br /&gt; Please change reduce and split parameter &lt;br /&gt; &lt;/span&gt;&#39;, unsafe_allow_html=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*t-9Ax_BBKPjonhtxsJVrvg.png" /></figure><h4>3. Choose the algorithm:</h4><p>Now we will add another “<strong><em>selectbox</em></strong>” on the sidebar to enable algorithm selection like “<strong><em>Classification</em></strong><em>” </em>or “<strong><em>Regression</em></strong>”. Then, depending on previous selection we will add new selectbox with available methods for the chosen algorithm type.</p><p>Additionally, in order to present algorithm parameter selection, we also add <em>“</em><strong><em>slider</em></strong><em>” gadget to take input from the user.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*iFMLFpsJ2UNPHQkpDJV1rQ.png" /><figcaption>Algroithm type and method selection</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*siB1-XShVnx9yJUML5pulg.png" /><figcaption>Parameter selection</figcaption></figure><pre><strong>def set_classifier_properties(self):<br>   </strong>self.type = st.sidebar.selectbox(“Algorithm type”, (“Classification”, “Regression”))</pre><pre>   if self.type == “Regression”:<br>      self.chosen_classifier = st.sidebar.selectbox(“Please choose a classifier”, (‘Random Forest’, ‘Linear Regression’, ‘Neural Network’))</pre><pre>   if self.chosen_classifier == ‘Random Forest’:<br>      self.n_trees = st.sidebar.slider(‘number of trees’, 1, 1000, 1)<br>   elif self.chosen_classifier == ‘Neural Network’:<br>      self.epochs = st.sidebar.slider(‘number of epochs’, 1 ,100 ,10)<br>      self.learning_rate = float(st.sidebar.text_input(‘learning rate:’, ‘0.001’))<br>   elif self.type == “Classification”:<br>      self.chosen_classifier = st.sidebar.selectbox(“Please choose a classifier”, (‘Logistic Regression’, ‘Naive Bayes’, ‘Neural Network’))<br>   if self.chosen_classifier == ‘Logistic Regression’:<br>      self.max_iter = st.sidebar.slider(‘max iterations’, 1, 100, 10)<br>   elif self.chosen_classifier == ‘Neural Network’:<br>      self.epochs = st.sidebar.slider(‘number of epochs’, 1 ,100 ,10)<br>      self.learning_rate = float(st.sidebar.text_input(‘learning rate:’, ‘0.001’))<br>      self.number_of_classes = int(st.sidebar.text_input(‘Number of classes’, ‘2’))</pre><h4>4. Make the prediction:</h4><pre><strong>def predict(self, predict_btn):<br>   </strong>if self.type == “Regression”:<br>      if self.chosen_classifier == ‘Random Forest’:<br>         self.alg = RandomForestRegressor(max_depth=2, random_state=0, n_estimators=self.n_trees)<br>         self.model = self.alg.fit(self.X_train, self.y_train)<br>predictions = self.alg.predict(self.X_test)<br>         self.predictions_train = self.alg.predict(self.X_train)<br>         self.predictions = predictions</pre><pre>      elif self.chosen_classifier==’Linear Regression’:<br>         self.alg = LinearRegression()<br>         self.model = self.alg.fit(self.X_train, self.y_train)<br>         predictions = self.alg.predict(self.X_test)<br>         self.predictions_train = self.alg.predict(self.X_train)<br>         self.predictions = predictions<br>      <br>      elif self.chosen_classifier==’Neural Network’:<br>         model = Sequential()<br>         model.add(Dense(500, input_dim = len(self.X_train.columns), activation=’relu’,))<br>         model.add(Dense(50, activation=’relu’))<br>         model.add(Dense(50, activation=’relu’))<br>         model.add(Dense(1))<br>         model.compile(loss= “mean_squared_error” ,    optimizer=’adam’, metrics=[“mean_squared_error”])<br>         self.model = model.fit(self.X_train, self.y_train, epochs=self.epochs, batch_size=40)<br>         self.predictions = model.predict(self.X_test)<br>         self.predictions_train = model.predict(self.X_train)</pre><pre>   elif self.type == “Classification”:<br>      if self.chosen_classifier == ‘Logistic Regression’:<br>          self.alg = LogisticRegression()<br>          self.model = self.alg.fit(self.X_train, self.y_train)<br>          predictions = self.alg.predict(self.X_test)<br>          self.predictions_train = self.alg.predict(self.X_train)<br>          self.predictions = predictions</pre><pre>      elif self.chosen_classifier==’Naive Bayes’:<br>         self.alg = GaussianNB()<br>         self.model = self.alg.fit(self.X_train, self.y_train)<br>         predictions = self.alg.predict(self.X_test)<br>         self.predictions_train = self.alg.predict(self.X_train)<br>         self.predictions = predictions </pre><pre>      elif self.chosen_classifier==’Neural Network’:<br>         model = Sequential()<br>         model.add(Dense(500, input_dim = len(self.X_train.columns), activation=’relu’))<br>         model.add(Dense(50, activation=’relu’))<br>         model.add(Dense(50, activation=’relu’))<br>         model.add(Dense(self.number_of_classes, activation=’softmax’))<br>         optimizer = tf.keras.optimizers.SGD(lr=self.learning_rate, decay=1e-6, momentum=0.9, nesterov=True)<br>         model.compile(optimizer=’adam’, loss=’sparse_categorical_crossentropy’, metrics=[‘accuracy’])<br>         self.model = model.fit(self.X_train, self.y_train, epochs=self.epochs, batch_size=40)<br>         self.predictions = model.predict_classes(self.X_test)<br>         self.predictions_train = model.predict_classes(self.X_train)</pre><h4>5. Plot the Results and Calculate metrics</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*7EC3EYYjJO7lvKW64zxNiA.png" /></figure><pre><strong>def get_metrics(self):<br>   </strong>self.error_metrics = {}<br>   if self.type == &#39;Regression&#39;:<br>      self.error_metrics[&#39;MSE_test&#39;] = mean_squared_error(self.y_test, self.predictions)<br>      self.error_metrics[&#39;MSE_train&#39;] = mean_squared_error(self.y_train, self.predictions_train)</pre><pre>      return st.markdown(&#39;### MSE Train: &#39; + str(round(self.error_metrics[&#39;MSE_train&#39;], 3)) +</pre><pre>&#39; -- MSE Test: &#39; + str(round(self.error_metrics[&#39;MSE_test&#39;], 3)))<br>   elif self.type == &#39;Classification&#39;:<br>      self.error_metrics[&#39;Accuracy_test&#39;] = accuracy_score(self.y_test, self.predictions)<br>      self.error_metrics[&#39;Accuracy_train&#39;] = accuracy_score(self.y_train, self.predictions_train)<br>      return st.markdown(&#39;### Accuracy Train: &#39; + str(round(self.error_metrics[&#39;Accuracy_train&#39;], 3)) +</pre><pre>&#39; -- Accuracy Test: &#39; +  str(round(self.error_metrics[&#39;Accuracy_test&#39;], 3)))</pre><pre><strong>def plot_result(self):<br>   </strong>output_file(&quot;slider.html&quot;)<br>   s1 = figure(plot_width=800, plot_height=500, background_fill_color=&quot;#fafafa&quot;)<br>   s1.circle(self.result_train.index, self.result_train.Actual_Train, size=12, color=Set3[5][3], alpha=1)<br>   s1.triangle(self.result_train.index, self.result_train.Prediction_Train, size=12, color=Set3[5][4], alpha=1)<br>   tab1 = Panel(child=s1, title=&quot;Train Data&quot;)</pre><pre>   if self.result.Actual is not None:<br>      s2 = figure(plot_width=800, plot_height=500, background_fill_color=&quot;#fafafa&quot;)<br>      s2.circle(self.result.index, self.result.Actual, size=12, color=Set3[5][3], alpha=1)<br>      s2.triangle(self.result.index, self.result.Prediction, size=12, color=Set3[5][4], alpha=1)<br>      tab2 = Panel(child=s2, title=&quot;Test Data&quot;)<br>      tabs = Tabs(tabs=[ tab1, tab2 ])</pre><pre>   else:<br>      tabs = Tabs(tabs=[ tab1])<br>st.bokeh_chart(tabs)</pre><p><strong><em>6. Conclusion:</em></strong></p><p>You can run the project on ypur default web browser by running the command <strong><em>“streamlit run main_script.py”</em></strong> from your terminal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/407/1*rBBO50wc2MrCGk58tiSdig.png" /></figure><p>The full application will be like below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aa091Zf-2_N0_etBK19qBQ.png" /></figure><blockquote><strong><em>This is the end of Chapter 1. In the next chapter we will deploy this app on Heroku. You can find the full project in my repo:</em></strong></blockquote><p><a href="https://github.com/utkuarik/ml_webapp">utkuarik/ml_webapp</a></p><blockquote><strong><em>You can also check out my other articles:</em></strong></blockquote><ul><li><a href="https://medium.com/@utkuarik/introduction-to-pandas-and-data-analysis-19d299c7cb78">Introduction to Pandas and Data Analysis</a></li><li><a href="https://medium.com/@utkuarik/chapter-1-a-kind-of-ising-schelling-model-902133cf6f85">Chapter 1-A kind of Ising-Schelling Model</a></li><li><a href="https://medium.com/@utkuarik/estimating-pi-value-with-monte-carlo-simulation-python-5d8a2cedbab9">Estimating Pi value with Monte Carlo simulation (Python)</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7864e04c1fbf" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/machine-learning-web-app-with-streamlit-7864e04c1fbf">Machine Learning Web App with Streamlit</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Introduction to Pandas and Data Analysis]]></title>
            <link>https://medium.com/@utkuarik/introduction-to-pandas-and-data-analysis-19d299c7cb78?source=rss-d2faa75732bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/19d299c7cb78</guid>
            <category><![CDATA[pandas]]></category>
            <category><![CDATA[data-analysis]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Utku Arık]]></dc:creator>
            <pubDate>Wed, 18 Mar 2020 12:38:42 GMT</pubDate>
            <atom:updated>2020-04-24T18:55:54.246Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*lfKiJlaRo9HQIlq_" /><figcaption>Photo by <a href="https://unsplash.com/@srd844?utm_source=medium&amp;utm_medium=referral">Stephen Dawson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p><strong>1- Download FIFA 19 player dataset from Kaggle link:</strong></p><p><a href="https://www.kaggle.com/karangadiya/fifa19">FIFA 19 complete player dataset</a></p><p><strong>2- Let’s import the pandas, read the data and check column names:</strong></p><pre>import pandas as pd<br>data = pd.read_csv(&#39;data.csv&#39;)<br>data.columns</pre><p>In here, <strong><em>read_csv</em></strong> method makes us to read a csv file as pandas built in Data Frame data type.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VV3UDUKKczKvv-sYADS0YA.png" /></figure><p><strong>3- Get some descriptive statistics</strong></p><p>With describe method we can get some statistical information about our dataset.</p><pre>data.describe()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LrbXJiMcIdA4dEyGTLmD2g.png" /></figure><p><strong>4- Count the number of players by each country:</strong></p><p><strong><em>groupby</em></strong> method helps us to group the data by desired columns and apply a function to each specific group for these columns:</p><pre>data[[&#39;ID&#39;,&#39;Nationality&#39;]].groupby([&#39;Nationality&#39;]).count().sort_values(by=&#39;ID&#39;, ascending=False).head(10)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*YdCO2EySzBpZo_Vd0wlkag.png" /><figcaption><strong>The number of players by each country</strong></figcaption></figure><p><strong>5- Turkish players with highest potentials:</strong></p><pre>data.loc[data[&#39;Nationality&#39;] == &#39;Turkey&#39;, [&#39;Name&#39;, &#39;Potential&#39;,&#39;Value&#39;]].sort_values(by=&#39;Potential&#39;, ascending= False).head(15)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/956/1*nEyoypRGx8DXfzrpW60gvw.png" /><figcaption>Turkish players with highest potentials</figcaption></figure><p><strong>6- English players with highest potentials:</strong></p><pre>data.loc[data[&#39;Nationality&#39;] == &#39;England&#39;, [&#39;Name&#39;, &#39;Potential&#39;,&#39;Value&#39;]].sort_values(by=&#39;Potential&#39;, ascending= False).head(15)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*NKL1cA1FpkwW2vElORbZSA.png" /><figcaption>English players with highest potentials</figcaption></figure><p><strong>7- Average overall score for each nationality:</strong></p><p>In order to get statistically accurate average potentials for each nationality, we also need to think about the count of players for each nationality. Therefore, since we don’t want any bias i our data, we exclude the nations that have players less than 200.</p><p>When we use</p><pre>data[&#39;count&#39;] = data.groupby(&#39;Nationality&#39;)[&#39;ID&#39;].transform(&#39;count&#39;)</pre><pre>data.loc[data[&#39;count&#39;] &gt; 200].groupby([&#39;Nationality&#39;])[[&#39;Potential&#39;]].mean().sort_values(by=&#39;Potential&#39;, ascending= False)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*E9UYedebQaVwcC1fDi6hvw.png" /><figcaption>Average potential scores for nationalities</figcaption></figure><p><strong>8- Most valuable players</strong></p><p>First, we need to convert <em>‘value’</em> column:</p><pre>data[‘Value’] = data[‘Value’].apply(lambda x: x.replace(“€”, “”)) <br>data[‘Value’] = data[‘Value’].apply(lambda x: x.replace(“M”, “00000”) if “.” in x else x.replace(“M”, “000000”))<br>data[‘Value’] = data[‘Value’].apply(lambda x: x.replace(“K”, “000”)) <br>data[‘Value’] = data[‘Value’].apply(lambda x: x.replace(“.”, “”)) <br>data[‘Value’] = data[‘Value’].astype(“double”)<br></pre><p>Now, we can sort the players regarding their value:</p><pre>data[[&#39;Name&#39;,&#39;Value&#39;]].sort_values(by = &#39;Value&#39;, ascending= False).head(10).reset_index(drop=True)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/950/1*olzA1sCfrY8Vhxx2dNT1HA.png" /><figcaption>Most Valuable Players</figcaption></figure><p><strong>9-Let’s plot total value for top 10 club</strong></p><p>First, let’s import the required packages, in here we will use bokeh package for plotting.</p><pre>from bokeh.io import output_notebook, show<br>from bokeh.plotting import figure<br>import math</pre><p>Then we will give the name of the clubs and the value data as an input for the plot.</p><pre>output_notebook()<br>p = figure(x_range=top10club_by_value[&#39;Club&#39;], plot_height=400, title=&quot;Top 10 valuable clubs&quot;,<br>           toolbar_location=None, tools=&quot;&quot;)</pre><pre>p.vbar(x=top10club_by_value[&#39;Club&#39;], top=top10club_by_value[&#39;Value&#39;], width=0.9)</pre><pre>p.xgrid.grid_line_color = None<br>p.y_range.start = 0<br>p.xaxis.major_label_orientation = math.pi/2<br>p.yaxis.formatter.use_scientific = False</pre><pre>show(p, notebook_handle = True)</pre><p>Plot is going to be like below image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*JqFGcxkh5w-WR01Bc52kvA.png" /></figure><h3>This article is not finished and it will be expanded regularly. Thanks for reading.</h3><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=19d299c7cb78" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Chapter 1-A kind of Ising-Schelling Model]]></title>
            <link>https://medium.com/@utkuarik/chapter-1-a-kind-of-ising-schelling-model-902133cf6f85?source=rss-d2faa75732bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/902133cf6f85</guid>
            <category><![CDATA[agent-based-modeling]]></category>
            <category><![CDATA[thomas-schelling]]></category>
            <category><![CDATA[simulation]]></category>
            <dc:creator><![CDATA[Utku Arık]]></dc:creator>
            <pubDate>Tue, 03 Dec 2019 20:47:47 GMT</pubDate>
            <atom:updated>2019-12-04T11:08:12.959Z</atom:updated>
            <content:encoded><![CDATA[<h3>Chapter 1- A kind of Ising-Schelling Model</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*m8TVfi_rbVlo3xtY" /><figcaption>Photo by <a href="https://unsplash.com/@clemhlrdt?utm_source=medium&amp;utm_medium=referral">Clément H</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In this article, I will give a brief introduction about a kind of Ising-Schelling model with different lower and upper bound thresholds limits. Ising-Schelling models usually consist of a regular lattice network with there are agents(in Ising model, electrons) that are located on these lattices.</p><p>Additionally, periodic boundary conditions(torus model)are hold for the model. This means that the edges of the lattice connected to each other. For example, I you move until the end of the right edge, you will come up from the left side.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/304/1*oM4VlkEPVCoDTyDDHEvm5Q.png" /><figcaption>Fig 1: Periodic boundary, the red agent is connected to all of the green agents</figcaption></figure><p>As I mentioned before the network consists of agents, An agent is classified as “<strong>unhappy</strong>” at each time step if the proportion of the total number of neighbors which are the same type as this agent over the total number of neighbors is not greater than or equal to the lower bound of the agent. Then at that time step, these unhappy agents start to convert themselves to other type.</p><p>The simulation starts with randomly located agents on the network, and in this setup, all of the cells are filled by the agents so there is no any vacant cells. There is 1/2 chance for each cell to become red or green.Therefore, in the initial configuration the proportion of the green and red agents are almost equal. After the simulations starts, at each time step, we determine the all of the unhappy agents and insert them to a <strong><em>unhappy list. </em></strong>Further<strong><em>,</em></strong><em> </em>at that time step, we pick a random agent from that list to convert it to opposite type and exclude it from the unhappy list. Next we pick another agent from the list, however that new chosen agent might have become happy by the conversions of the previously chosen agents. Therefore, even if the agent is in the unhappy list we again need to check if it is still unhappy. When there is no unhappy agent left in the list, the time step ends and simulation moves to the next time step. We repeat these same process for each time step and the algorithm finishes until there is no unhappy agent left in the network.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/240/1*AIGVFqVLf-Azutcg7RaTXw.gif" /><figcaption>Fig 2: Time evolution of the simulation</figcaption></figure><h3><strong>Pseudo Code</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ORNtfy3YdDc-uhbLBP2ylQ.png" /><figcaption>Pseudo code of the algorithm</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=902133cf6f85" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Estimating Pi value with Monte Carlo simulation (Python)]]></title>
            <link>https://medium.com/@utkuarik/estimating-pi-value-with-monte-carlo-simulation-python-5d8a2cedbab9?source=rss-d2faa75732bd------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d8a2cedbab9</guid>
            <category><![CDATA[monte-carlo]]></category>
            <category><![CDATA[pi]]></category>
            <category><![CDATA[special-numbers]]></category>
            <category><![CDATA[python]]></category>
            <dc:creator><![CDATA[Utku Arık]]></dc:creator>
            <pubDate>Thu, 16 May 2019 10:16:17 GMT</pubDate>
            <atom:updated>2019-07-24T07:27:42.114Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*xyU7R0WQQ3LpMlb_" /><figcaption>Photo by <a href="https://unsplash.com/@roman_lazygeek?utm_source=medium&amp;utm_medium=referral">Roman Mager</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>One can easily estimate pi value by implementing simple simulation experiments. In the below codes, we apply basic monte carlo method to approximate the real value of pi. <strong><em>The main story of the experiment is if we have a perfectly fit circle in a square, and if we start to toss coins inside to this square, at the end, how many coins would we have in the circle.</em></strong></p><p>This experiment will help us to approximate the real pi value. Since if we assume the length of the one side of the square as “<strong><em>r”, </em></strong><em>the ratio of the area of circle /area of the square will be “</em>π/4”. This means that the ratio of the number of coins inside the circle / the total number of coins we toss(n) is also approximating to <em>“</em>π/4”. Therefore if we increase the our experiment size “n”( total #of tosses) then the result will slowly approach to pi value.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1a730e3b6bb39d0af0b179a938d2954d/href">https://medium.com/media/1a730e3b6bb39d0af0b179a938d2954d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ec1767f240628f8896fcb49435347539/href">https://medium.com/media/ec1767f240628f8896fcb49435347539/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/089c8ca9952ef1b1eb4133f20d55c85d/href">https://medium.com/media/089c8ca9952ef1b1eb4133f20d55c85d/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/60eec246045ab351c32277e91d15735d/href">https://medium.com/media/60eec246045ab351c32277e91d15735d/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d8a2cedbab9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>