-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathcheatsheet.txt
More file actions
141 lines (85 loc) · 4.34 KB
/
cheatsheet.txt
File metadata and controls
141 lines (85 loc) · 4.34 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
##################################################################################################
# #
# collection of some useful pandas,Numpy and matplotlib function useful in times of data wrangling and processing. # # #
##################################################################################################
import pandas as pd
---make data frame---
df = pd.read_csv('train.csv',delimiter="\t",header=0,names=[])
df.dtypes
df.head() --> print top 5 data
df.columns.values ---> all columns names as list
df["column_name"].median()
df['colum_name'] -->>dtype of series
df[["co1","col2","col3"]]
df["new column"] = value
df.info()
df.describe()
df.describe()["column_name"] or df["column_name"].describe()
df['column_name'] = df.['column_name'].fillna(value) --> to replace empty or nan
df.loc[df["column_name"]=="male","column_name"]=0 -->to locate and replace male with o i nsex column
df["column_name"].unique() -->gives all the unique values in embarked column
df[df['Age'] > 60]
df[df['Age'] > 60][['Sex', 'Pclass', 'Age', 'Survived']]
len(df[ (df['Sex'] == 'male') & (df['Pclass'] == i) ])
df['Gender'] = df['Sex'].map( {'female': 0, 'male': 1} ).astype(int)
df.drop([col1,col2,....],axis=1(alg column)/0(alf row)) --> todelte columns
df.values -->covert df to numpy ARRAY
np.array(df)
-----------------NUMPY-------------------------------
2d vector space
x = np.array(x)
x = [
[1,2,3],
[4,5,6]
]
x[0] --> [1,2,3] or x[:][0]
x[0][0] --.[1]
x[:] or x
x[::,2] --> This outputs the 3rd column x[row,column]
x[::,1:4] -->This output the column values from 1 to 3rd column for all rows
x.reshape(-1,2) --> -1 adjusts the shape according to other dimensions
x.shape
----------------MATPLOTLIB----------------------------------------------
---------------------- TENSORFLOW ----------------------------------------
# Create a variable.
w = tf.Variable(<initial-value>, name=<optional-name>)
tf.placeholder(dtype, shape=None, name=None)
tf.truncated_normal(shape, mean=0.0, stddev=1.0, dtype=tf.float32, seed=None, name=None)
tf.zeros(shape, dtype=tf.float32, name=None)
tf.nn.relu(features, name=None)
features: A Tensor. Must be one of the following types: float32, float64, int32, int64, uint8, int16, int8, uint16, half.
tf.matmul(mat1,mat2)
tf.nn.sparse_softmax_cross_entropy_with_logits(logits, labels, name=None)
logits must have the shape [batch_size, num_classes] and dtype float32 or float64.
labels must have the shape [batch_size] and dtype int32 or int64.
tf.scalar_summary(tags, values, collections=None, name=None)
tags: A string Tensor. Tags for the summaries.
values: A real numeric Tensor. Values for the summaries.
collections: Optional list of graph collections keys. The new summary op is added to these collections. Defaults to [GraphKeys.SUMMARIES].
name: A name for the operation (optional).
tf.train.GradientDescentOptimizer(learning_rate, use_locking=False, name='GradientDescent')
learning_rate: A Tensor or a floating point value. The learning rate to use.
use_locking: If True use locks for update operations.
name: Optional name prefix for the operations created when applying gradients. Defaults to "GradientDescent".
sess = tf.Session(graph = )
computed_x = sess.run(x)
or
computed_x = x.eval()
sess = tf.InteractiveSession()
g = tf.get_default_graph() ------>defaut graph in tensorflow all operation added to it
g1 = tf.Graph()
g1.get_operations().name
with g1.as_default():
c = tf.constant(30.0)
w = g.get_tensor_by_name('layer1/W:0')
with tf.name_scope(name):
a = tf.convert_to_tensor(a, name="a") -->name/a:0
b = tf.convert_to_tensor(b, name="b")
--------convolutions--------------------------------
tf.nn.conv2d(input, filter, strides, padding, use_cudnn_on_gpu=None, data_format=None, name=None)
input = [batch, in_height, in_width, in_channels]
filter = [filter_height, filter_width, in_channels, out_channels]
strides = [1,1,1,1] or [1,2,2,1]
[input,stride_height,stride_width,channel]
padding = 'VALID'-> size will change
'SAME' -> 0 padded to retain n the original shape