- 博客(126)
- 收藏
- 关注
原创 TensorFlow2.x 学习笔记(八)过拟合
过拟合与欠拟合 Model capacity 当模型的复杂度增强时,模型的表达性也随之增强,以多项式为例 y=β0+β1x+β2x2+...+βnxn+ϵy = \beta_0 + \beta_1x + \beta_2x^2 + ... + \beta_nx^n + \epsilony=β0+β1x+β2x2+...+βnxn+ϵ 随着阶数的增加,可表示的模型也就越多,模型的表示能力也就越强。 Underfitting model capacity < ground truth train
2020-05-13 04:36:46
346
原创 TensorFlow2.x 学习笔记(七)Keras高层接口
Keras高层接口 这里所指的均为tf.keras Keras高层API metrics acc_meter = metrics.Accuracy() loss_meter = metrics.Mean() update_state loss_meter.update_state(loss) acc_meter.udate_state(y, pred) result().numpy() pri...
2020-04-14 04:07:38
375
原创 TensorFlow2.x 学习笔记(六)随机梯度下降以及数据可视化
梯度下降 简介 梯度 梯度是一个向量,表示某一函数在该点处的方向导数沿着该方向取得最大值。 gradf(x,y)=∇f(x,y)=(∂f∂x,∂f∂y)=∂f∂xi+∂f∂xjgradf(x,y) = \nabla{f(x,y)} = (\frac{\partial f}{\partial x},\frac{\partial f}{\partial y}) = \frac{\partial f}{...
2020-04-09 03:18:29
721
原创 TensorFlow2.x 学习笔记(五)神经网络与全连接层
数据加载 keras.datasets boston housing Boston housing price regression dataset mnist/fashion mnist MNIST/Fashion-MNIST dataset MNIST (x, y), (x_test, y_test) = keras.datasets.mnist.load_data() x.shape...
2020-03-19 03:59:58
587
原创 [LeetCode 1351~1354][周赛]周赛176题解
这场周赛还是有点意思的,没有那么水,大概hard有cf div2 D的感觉 1351. 统计有序矩阵中的负数 题目链接 第一种:二分 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: ...
2020-03-05 03:36:03
282
原创 [LeetCode 1356~1359][周赛]双周赛20题解
根据数字二进制下 1 的数目排序 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: int cnt[10010]; vector<int> sor...
2020-03-04 01:46:47
244
原创 [LeetCode 1360~1363][周赛]周赛177题解
1360.日期之间隔几天 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: int nleap[13]={0, 31, 28, 31, 30, 31, 30, 31, 3...
2020-03-02 17:50:23
291
原创 [LeetCode 1365~1368][周赛]周赛178题解
5344.有多少小于当前数字的数字 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: vector<int> smallerNumbersThanCurren...
2020-03-01 14:38:16
296
原创 TensorFlow2.x 学习笔记(三)基础操作
数据类型 python Data Container list :消耗大 np.array :无GPU tf.tensor TF is a computing lib Creat tf.constant(1) # int tf.constant(1.) # float32 tf.constant(2.2, dtype=tf.int32) # error tf.constant(2., dtyp...
2020-03-01 03:49:17
408
原创 TensorFlow2.x 学习笔记(二)回归问题&分类问题
fθ:x→yf_{\theta}: x\rightarrow yfθ:x→y yyy通常可以分为两类:离散或连续 连续时为回归问题 linear regression loss function gradient descent loss surface convex Optimization linear regression linear Regression logistic Regr...
2020-03-01 03:48:54
262
原创 TensorFlow2.x 学习笔记(四)高级操作
合并与分割 Merge and split tf.concat [class1-4, students, scores] [class5-6, students, scores] a = tf.ones([4,35,8]) b = tf.ones([2,35,8]) c = tf.concat([a,b], axis=0) c.shape a = tf.ones([4,32,8]) b =...
2020-03-01 03:47:37
343
原创 [LeetCode 404, 405][简单]左叶子之和/数字转换为十六进制数
404.左叶子之和 题目链接 static const auto io_speed_up =[](){ ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); return 0; }(); class Solution { public: int sumOfLeftLeaves(TreeNode* root...
2020-02-29 16:06:32
263
原创 [LeetCode 392,401][简单]判断子序列/二进制手表
392.判断子序列 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); return NULL; }(); class Solution { public: bool isSubsequence(strin...
2020-02-28 16:01:35
212
原创 [LeetCode 387,389][简单]字符串中的第一个唯一字符/找不同
387.字符串中的第一个唯一字符 题目链接 static const auto io_speed_up = [](){ ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: int firstUniqChar(string s) { int f...
2020-02-27 16:25:02
167
原创 [LeetCode 374,383][简单]猜数字大小/赎金信
374.猜数字大小 题目链接 static const auto io_speed_up = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }(); int guess(int num); class Solution { public: typedef long long LL; int gu...
2020-02-26 17:24:27
250
原创 [LeetCode 367,371][简单]有效的完全平方数/两整数之和
367.有效的完全平方数 题目链接 static const auto io_speed_up = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }(); class Solution { public: bool isPerfectSquare(int num) { double ans...
2020-02-25 15:13:47
162
原创 [LeetCode 349,350][简单]两个数组的交集/两个数组的交集 II
349.两个数组的交集 题目链接 static const auto io_speed_up = []() { ios::sync_with_stdio(0); cin.tie(0); return 0; }(); class Solution { public: vector<int> intersection(vector<int>&am...
2020-02-24 15:46:37
165
原创 [LeetCode 344,345][简单]反转字符串/反转字符串中的元音字母
344.反转字符串 题目链接 static const auto io_speed_up = []() { ios::sync_with_stdio(false); cin.tie(0); return 0; }(); class Solution { public: void reverseString(vector<char>& s) {...
2020-02-23 16:59:24
197
原创 [LeetCode 326,342][简单]3的幂/4的幂
326.3的幂 题目链接 比较好想的是取对数法。 class Solution { public: double eps = 1e-11; bool isPowerOfThree(int n) { if(n<=0)return 0; double pw = log2(n) / log2(3.0); return fabs(rou...
2020-02-23 16:32:21
250
原创 [LeetCode 299,303][简单]猜数字游戏/区域和检索 - 数组不可变
299.猜数字游戏 题目链接 class Solution { public: string getHint(string secret, string guess) { ios::sync_with_stdio(0); cin.tie(0); int a[10]={0},b[10]={0}; int acnt=0,bcnt=...
2020-02-22 22:39:14
417
原创 [LeetCode 290,292][简单]单词规律/Nim 游戏
290.单词规律 题目链接 class Solution { public: bool wordPattern(string pattern, string str) { ios::sync_with_stdio(0); cin.tie(0); istringstream iss(str); unordered_map<...
2020-02-21 15:17:25
181
原创 [LeetCode 278,283][简单]第一个错误的版本/移动零
278.第一个错误的版本 题目链接 // Forward declaration of isBadVersion API. bool isBadVersion(int version); class Solution { public: typedef long long LL; int firstBadVersion(int n) { LL l = 1, r =...
2020-02-20 17:49:54
190
原创 [LeetCode 263,268][简单]丑数/缺失数字
263.丑数 题目链接 class Solution { public: bool isUgly(int num) { while(num&&(num&1)==0)num>>=1; while(num&&(num%3)==0)num/=3; while(num&&(num%5...
2020-02-19 13:32:23
258
原创 [LeetCode 257,258][简单]二叉树的所有路径/各位相加
257.二叉树的所有路径 题目链接 class Solution { public: vector<string>ans; string path=""; void getans(TreeNode* root,string path){ if(root)path += to_string(root->val); else r...
2020-02-18 18:06:30
162
原创 [LeetCode 237,242][简单]删除链表中的节点/有效的字母异位词
237.删除链表中的节点 题目链接 class Solution { public: void deleteNode(ListNode* node) { *node = *(node -> next); } }; 242.有效的字母异位词 题目链接 class Solution { public: bool isAnagram(string s, s...
2020-02-17 18:33:42
167
原创 [LeetCode 234,235][简单]回文链表/二叉搜索树的最近公共祖先
234.回文链表 题目链接 class Solution { public: bool isPalindrome(ListNode* head) { ListNode *h = head; ListNode *f = new ListNode(0); ListNode *s = new ListNode(0); f->n...
2020-02-16 19:26:13
181
原创 [LeetCode 231,232][简单]2的幂/用栈实现队列
231.2的幂 题目链接 class Solution { public: bool isPowerOfTwo(int n) { return n>0 && !(n&-n^n); } }; 232.用栈实现队列 题目链接 class MyQueue { public: /** Initialize your data stru...
2020-02-15 18:05:24
162
原创 [LeetCode 225,226][简单]用队列实现栈/翻转二叉树
225.用队列实现栈 题目链接 class MyStack { public: /** Initialize your data structure here. */ deque<int>mq; int tp; MyStack() { } /** Push element x onto stack. */ ...
2020-02-14 16:12:58
215
原创 [LeetCode 217,219][简单]存在重复元素/存在重复元素II
217.存在重复元素 题目链接 class Solution { public: bool containsDuplicate(vector<int>& nums) { unordered_set<int>ms; for(auto i : nums){ if(ms.count(i))return tru...
2020-02-13 16:13:49
205
原创 [LeetCode 205,206][简单]同构字符串/反转链表
205.同构字符串 题目链接 只用比较每个字符上一次出现的位置是否一致 class Solution { public: int mps[256],mpt[256]; bool isIsomorphic(string s, string t) { memset(mps,-1,sizeof mps); memset(mpt,-1,sizeof mpt)...
2020-02-12 12:36:02
154
原创 [LeetCode 203,204][简单]移除链表元素/计数质数
203.移除链表元素 题目链接 比较通用的思路是加一个dummyhead,那我就用二级指针做一下 class Solution { public: ListNode* removeElements(ListNode* head, int val) { ListNode **p = &head; while(*p){ if((*...
2020-02-11 19:07:20
212
原创 [LeetCode 198,202][简单]打家劫舍/快乐数
198.打家劫舍 题目链接 dp[n]=max(dp[n−1],dp[n−2]+w[n])dp[n] = max(dp[n-1],dp[n-2]+w[n])dp[n]=max(dp[n−1],dp[n−2]+w[n]) 可以滚动优化一下空间 class Solution { public: int rob(vector<int>& nums) { int...
2020-02-10 17:31:35
267
原创 [LeetCode 190,191][简单]颠倒二进制位/位1的个数
190.颠倒二进制位 题目链接 贴一个纯位运算的版本和一个纯bitset的版本 class Solution { public: uint32_t reverseBits(uint32_t n) { bitset<32>a(n); string tmp = a.to_string(); reverse(tmp.begin(), t...
2020-02-09 18:27:16
269
原创 [LeetCode 172,189][简单]阶乘后的零/旋转数组
172.阶乘后的零 题目链接 10 = 2 * 5,比n小是2的倍数的数肯定比是5的多,所以只需要看因子5出现的次数 class Solution { public: int trailingZeroes(int n) { int ans = 0; while(n){ n/=5; ans += n; ...
2020-02-08 19:10:37
266
原创 [LeetCode 169,171][简单]多数元素/Excel表列序号
169.多数元素 题目链接 比较显然的做法是排个序后取中间元素和哈希表 看了下题解发现最后一个方法比较巧妙,叫做Boyer-Moore 投票算法,就是先把第一个元素设置为候选,然后循环过程中对候选+1,非候选 -1,到零后把下一个元素置为候选,最后的候选就是真值,简单证明下: 候选为真,则最多删掉同样数量的候选与非候选 候选为假 删掉更多的非候选,对结果无影响 删掉同样多的非候选与候选 真...
2020-02-07 14:48:21
277
原创 [LeetCode 111,168][简单]二叉树的最小深度/Excel表列名称
111.二叉树的最小深度 题目链接 之前漏掉了,补上 class Solution { public: int minDepth(TreeNode* root) { if(root == NULL)return 0; if(root->left && root->right) return min(minDepth(root -&...
2020-02-06 18:04:33
229
原创 [LeetCode 160,167][简单]相交链表/两数之和 II - 输入有序数组
160.相交链表 题目链接 class Solution { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ios::sync_with_stdio(false); if(!(headA&&headB))return NULL; ...
2020-02-06 02:31:02
168
原创 [LeetCode 141,155][简单]环形链表/最小栈
141.环形链表 题目链接 显然的做法是用unordered_map,节约空间可以用快慢指针。 class Solution { public: bool hasCycle(ListNode *head) { ios::sync_with_stdio(false); if(!(head && head -> next))return f...
2020-02-05 21:41:29
240
原创 [LeetCode 125,136][简单]验证回文串/只出现一次的数字
125.验证回文串 题目链接 class Solution { public: bool isv(char p){ if(p<='z' && p>='a')return true; if(p<='9' && p>='0')return true; return false; } ...
2020-02-04 23:17:30
178
原创 [LeetCode 121,122][简单]买卖股票的最佳时机/买卖股票的最佳时机II
121.买卖股票的最佳时机 题目链接 class Solution { public: int maxProfit(vector<int>& prices) { int mn=INT_MAX,ans=0; for(int i=1,siz=prices.size();i<siz;i++){ mn = min(m...
2020-02-04 21:45:36
181
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人