I wrote about the solutions to some problems I found from programming and data analytics. They may help you on your work. Thank you.
ezoic
Friday, May 18, 2018
Wednesday, May 16, 2018
some python code to plot subplots in python
import matplotlib.pyplot as plt
import numpy as np
# Simple data to display in various forms
x = np.linspace(0, 2 * np.pi, 400)
y = np.sin(x ** 2)
plt.close('all')
# Just a figure and one subplot
f, ax = plt.subplots()
ax.plot(x, y)
ax.set_title('Simple plot')
# Two subplots, the axes array is 1-d
f, axarr = plt.subplots(2, sharex=True)
axarr[0].plot(x, y)
axarr[0].set_title('Sharing X axis')
axarr[1].scatter(x, y)
# Two subplots, unpack the axes array immediately
f, (ax1, ax2) = plt.subplots(1, 2, sharey=True)
ax1.plot(x, y)
ax1.set_title('Sharing Y axis')
ax2.scatter(x, y)
# Three subplots sharing both x/y axes
f, (ax1, ax2, ax3) = plt.subplots(3, sharex=True, sharey=True)
ax1.plot(x, y)
ax1.set_title('Sharing both axes')
ax2.scatter(x, y)
ax3.scatter(x, 2 * y ** 2 - 1, color='r')
# Fine-tune figure; make subplots close to each other and hide
x ticks for
# all but bottom plot.
f.subplots_adjust(hspace=0)
plt.setp([a.get_xticklabels() for a in f.axes[:-1]], visible=False)
# row and column sharing
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, sharex='col', sharey='row')
ax1.plot(x, y)
ax1.set_title('Sharing x per column, y per
row')
ax2.scatter(x, y)
ax3.scatter(x, 2 * y ** 2 - 1, color='r')
ax4.plot(x, 2 * y ** 2 - 1, color='r')
# Four axes, returned as a 2-d array
Thursday, May 10, 2018
Scrapy linux cron job not work, how I make it work
I tried to automate a scrapy job using cron on linux. But it did not work. I searched and found the solution.
First use "which scrapy " to find where the scrapy is. For my machine the scrapy is:
/home/ubuntu/anaconda2/bin/scrapy
First use "which scrapy " to find where the scrapy is. For my machine the scrapy is:
/home/ubuntu/anaconda2/bin/scrapy
Then in the shell script, write:
cd /path/to/spider
nohup /home/ubuntu/anaconda2/bin/scrapy crawl quotes >> log.txt &
It resolved the problem. Or can write:
cd /path/to/spider
PATH=$PATH:/home/ubuntu/anaconda2/bin
export PATH
nohup /home/ubuntu/anaconda2/bin/scrapy crawl quotes >> log.txt &
Tuesday, May 8, 2018
Compare Unix date and time
Compare Unix date and time.
To get Unix time, the command is:
current time:
now=`date +"%T"`
we will get a time like "20:55:01"
now=`date +"%H%M%S"`
we will get a time like "205501"
If we want to compare times, we can not compare the times in the format "%H:%M:%S", we can only compare them in the format "%H%M%S". Otherwise we will get an error Illegal number: 20:59:22
To get Unix date, the command is:
date1=`date +"%m/%d/%Y %H:%M:%S"`
We will get a date in like "5/8/2018 20:55:01"
If we want to get timestamp, we will use:
date2=`date +"%s"`
we will get a unix timestamp.
we can compare dates by its unix timestamp. it seems we can not compare two dates like "5/8/2018 20:55:01". Otherwise we will get an error: Illegal number: 05/08/2018 20:59:22.
To get Unix time, the command is:
current time:
now=`date +"%T"`
we will get a time like "20:55:01"
now=`date +"%H%M%S"`
we will get a time like "205501"
If we want to compare times, we can not compare the times in the format "%H:%M:%S", we can only compare them in the format "%H%M%S". Otherwise we will get an error Illegal number: 20:59:22
To get Unix date, the command is:
date1=`date +"%m/%d/%Y %H:%M:%S"`
We will get a date in like "5/8/2018 20:55:01"
If we want to get timestamp, we will use:
date2=`date +"%s"`
we will get a unix timestamp.
we can compare dates by its unix timestamp. it seems we can not compare two dates like "5/8/2018 20:55:01". Otherwise we will get an error: Illegal number: 05/08/2018 20:59:22.
Thursday, May 3, 2018
Linux Cron, linux job scheduler
Linux Cron, linux job scheduler
https://www.youtube.com/watch?v=4Icg3MYZZqI
https://awc.com.my/uploadnew/5ffbd639c5e6eccea359cb1453a02bed_Setting%20Up%20Cron%20Job%20Using%20crontab.pdf
to edit a cron file "crontab -e". Then you will run a job indefinitely.
Wednesday, May 2, 2018
implement decision tree from scratch using python
implement decision tree from scratch using python:
https://machinelearningmastery.com/implement-decision-tree-algorithm-scratch-python/
This guy has a good blog:
https://machinelearningmastery.com/blog/
Subscribe to:
Posts (Atom)
looking for a man
I am a mid aged woman. I was born in 1980. I do not have any kid. no complicated dating before . I am looking for a man here for marriage...
-
I tried to commit script to bitbucket using sourcetree. I first cloned from bitbucket using SSH, and I got an error, "authentication ...
-
https://github.com/boto/boto3/issues/134 import boto3 import botocore client = boto3.client('s3') result = client.list_obje...
-
Previously, I wanted to install "script" on Atom to run PHP. And there was some problem, like the firewall. So I tried atom-runner...