목록전체 글 (462)
Note
How to compute the softmax score? # Input url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' iris = np.genfromtxt(url, delimiter=',', dtype='object') sepallength = np.array([float(row[0]) for row in iris]) # Solution def softmax(x): """Compute softmax values for each sets of scores in x. https://stackoverflow.com/questions/34968722/how-to-implement-the-softmax-funct..
How to create a TimeSeries starting ‘2000-01-01’ and 10 weekends (saturdays) after that having random numbers as values? # Solution ser = pd.Series(np.random.randint(1,10,10), pd.date_range('2000-01-01', periods=10, freq='W-SAT')) ser # output 2000-01-01 6 2000-01-08 7 2000-01-15 4 2000-01-22 6 2000-01-29 8 2000-02-05 6 2000-02-12 5 2000-02-19 8 2000-02-26 1 2000-03-04 7 Freq: W-SAT, dtype: int64
How to normalize an array so the values range exactly between 0 and 1? # Input url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' sepallength = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0]) # 1 Smax, Smin = sepallength.max(), sepallength.min() S = (sepallength - Smin)/(Smax - Smin) # 2 S = (sepallength - Smin)/sepallength.ptp() print(S) # output [ 0...
How to replace missing spaces in a string with the least frequent character? # Input my_str = 'dbc deb abed gade' # Solution ser = pd.Series(list('dbc deb abed gade')) freq = ser.value_counts() print(freq) # output d 4 b 3 e 3 3 a 2 g 1 c 1 dtype: int64 least_freq = freq.dropna().index[-1] "".join(ser.replace(' ', least_freq)) # output 'dbccdebcabedcgade'
How to compute the mean, median, standard deviation of a numpy array? # Input url = 'https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data' iris = np.genfromtxt(url, delimiter=',', dtype='object') sepallength = np.genfromtxt(url, delimiter=',', dtype='float', usecols=[0]) # Solution mu, med, sd = np.mean(sepallength), np.median(sepallength), np.std(sepallength) print(mu, med, ..