BACKGROUND In order to alter the theme of Ant Design, there are multiple target files…
Hands On Machine Learning – Example 1.1 with CSV
Required CSV oecd_bli_2015.csv gdp_per_capita.csv prepare_country_stats()
1 2 3 4 5 6 7 8 9 10 11 12 13 |
def prepare_country_stats(oecd_bli, gdp_per_capita): oecd_bli = oecd_bli[oecd_bli["INEQUALITY"] == "TOT"] oecd_bli = oecd_bli.pivot( index="Country", columns="Indicator", values="Value") gdp_per_capita.rename(columns={"2015": "GDP per capita"}, inplace=True) gdp_per_capita.set_index("Country", inplace=True) full_country_stats = pd.merge(left=oecd_bli, right=gdp_per_capita, left_index=True, right_index=True) full_country_stats.sort_values(by="GDP per capita", inplace=True) remove_indices = [0, 1, 6, 8, 33, 34, 35] keep_indices = list(set(range(36)) - set(remove_indices)) return full_country_stats[["GDP per capita", 'Life satisfaction']].iloc[keep_indices] |
Completed code for example 1.1
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import pandas as pd import matplotlib import matplotlib.pyplot as plt import sklearn.linear_model import sklearn.neighbors import numpy as np def prepare_country_stats(oecd_bli, gdp_per_capita): oecd_bli = oecd_bli[oecd_bli["INEQUALITY"] == "TOT"] oecd_bli = oecd_bli.pivot( index="Country", columns="Indicator", values="Value") gdp_per_capita.rename(columns={"2015": "GDP per capita"}, inplace=True) gdp_per_capita.set_index("Country", inplace=True) full_country_stats = pd.merge(left=oecd_bli, right=gdp_per_capita, left_index=True, right_index=True) full_country_stats.sort_values(by="GDP per capita", inplace=True) remove_indices = [0, 1, 6, 8, 33, 34, 35] keep_indices = list(set(range(36)) - set(remove_indices)) return full_country_stats[["GDP per capita", 'Life satisfaction']].iloc[keep_indices] if __name__ == "__main__": oecd_bli = pd.read_csv("oecd_bli_2015.csv", thousands=',') gdp_per_capita = pd.read_csv( "gdp_per_capita.csv", thousands=',', delimiter='\t', encoding='latin1', na_values='n/a') country_stats = prepare_country_stats(oecd_bli, gdp_per_capita) country_stats.plot(kind='scatter', x="GDP per capita", y="Life satisfaction") X = np.c_[country_stats["GDP per capita"]] Y = np.c_[country_stats["Life satisfaction"]] model = sklearn.linear_model.LinearRegression() # model = sklearn.neighbors.KNeighborsRegressor(n_neighbors=3) model.fit(X, Y) for x in range(10, 50): plot_x = 1000 * x plot_y = float(model.predict([[plot_x]])) plt.scatter(plot_x, plot_y, s=10, color='r') plt.show() |
…
[UNITY] Character & map collision, Arrow key access
Character & map collision First of…
std::vector
Declaration
1 2 3 4 5 6 7 |
vector<int> v; // Size of 100 and initialize all to 0 vector<int> v(100, 0) // Reserve size of 3, to prevent extra complexity for copying v.reserve(3); |
Simple operation
1 2 |
int n; v.push_back(n); |
Fill with something
1 |
fill(v.begin(), v.end(), 101); |
Combine two vectors…
[Debug] no name in module error in pylint and flask
Problem The following errors occur in visual code editor
1 2 |
"message": "E0611:No name 'request' in module 'urllib'", "source": "pylint" |
Solution It should be…
[Debug] Vagrant vm setup – 3
Problem The following lines are not fatal error but still needed to be solved
1 2 3 4 |
==> default: Unknown device: enp0s8. Please specify device in "bus:slot.func" format ==> default: Unknown device: enp0s9. Please specify device in "bus:slot.func" format ==> default: Unknown device: enp0s10. Please specify device in "bus:slot.func" format ==> default: Unknown device: enp0s16. Please specify device in "bus:slot.func" format |
…
[Debug] Vagrant vm setup – 2
Problem The memory allocation failed during the vagrant up –provision
1 2 3 4 5 6 7 8 9 |
==> default: virtual memory exhausted: Cannot allocate memory ==> default: make[3]: ==> default: *** [virtio_net.o] Error 1 ==> default: make[2]: *** [librte_vhost] Error 2 ==> default: make[1]: *** [lib] Error 2 ==> default: make: *** [all] Error 2 ==> default: modprobe: FATAL: Module uio not found. ==> default: modprobe: FATAL: Module uio_pci_generic not found. ==> default: insmod: ERROR: could not insert module /home/vagrant/gatekeeper/dependencies/dpdk/build/kmod/igb_uio.ko: Unknown symbol in module |
Approach 1.…
[Debug] Vagrant vm setup – 1
Problem I’m trying to create the virtual machine using vagrant for the dpdk, however, the…
[libressl] Generate RSA key
In the latest version of libressl, RSA_generate_key is deprecated, RSA_generate_key_ex should be implemented instead. Implementation (updated) Source file (test.c)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
#include <openssl/rsa.h> #include <openssl/pem.h> int main(){ const int kBits = 2048; unsigned long e = RSA_F4; int keylen; char *pem_key; // BIGNUM PART BIGNUM* bignum = BN_new(); if(BN_set_word(bignum, e)) printf("[Debug] BIGNUM allocated!\n"); else printf("[Debug] BIGNUM NOT allocated!\n"); // RSA PART RSA *rsa = RSA_new(); if(RSA_generate_key_ex(rsa, 2048, bignum, NULL)) printf("[Debug] RSA allocated!\n"); else printf("[Debug] RSA NOT allocated!\n"); // BIO PART BIO *bio = BIO_new(BIO_s_mem()); PEM_write_bio_RSAPrivateKey(bio, rsa, NULL, NULL, 0, NULL, NULL); keylen = BIO_pending(bio); pem_key = calloc(keylen+1, 1); /* Null-terminate */ BIO_read(bio, pem_key, keylen); // OUTPUT printf("%s", pem_key); // FREE THE MEMORY BIO_free_all(bio); RSA_free(rsa); BN_free(bignum); free(pem_key); return 0; } |
…
[libressl] Setup
SETUP Install the dependencies first
1 2 |
sudo apt-get update sudo apt-get install automake autoconf git libtool perl |
Clone the repository from Github
1 |
git clone https://github.com/libressl-portable/portable.git libressl |
Prepare…