You have divergent branches and need to specify out of three options (merge, rebase, fast-forward) how to reconcile them. What to do?Let's experiment and figure out what these three reconciling strategies do.
Clone a Server Copy
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Already up to date. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git log commit b20128a7b6148aa7ed668cfe2531a54418e61097 (HEAD -> main, origin/main, origin/HEAD) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915Clone Three Local Copies
Local Copy 1
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1$ git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 39, done. remote: Counting objects: 100% (39/39), done. remote: Compressing objects: 100% (24/24), done. remote: Total 39 (delta 13), reused 23 (delta 4), pack-reused 0 Receiving objects: 100% (39/39), 8.45 KiB | 4.23 MiB/s, done. Resolving deltas: 100% (13/13), done.Local Copy 2
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2$ git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 39, done. remote: Counting objects: 100% (39/39), done. remote: Compressing objects: 100% (24/24), done. remote: Total 39 (delta 13), reused 23 (delta 4), pack-reused 0 Receiving objects: 100% (39/39), 8.45 KiB | 2.82 MiB/s, done. Resolving deltas: 100% (13/13), done.Local Copy 3
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3$ git clone https://github.com/ashishjain1547/repo_for_testing.git Cloning into 'repo_for_testing'... Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 39, done. remote: Counting objects: 100% (39/39), done. remote: Compressing objects: 100% (24/24), done. remote: Total 39 (delta 13), reused 23 (delta 4), pack-reused 0 Receiving objects: 100% (39/39), 8.45 KiB | 2.82 MiB/s, done. Resolving deltas: 100% (13/13), done. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3$Update the Server Copy
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ echo " " > 20220915_2336.html (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git commit -m "20220915 II" [main 80b40f5] 20220915 II 1 file changed, 1 insertion(+) create mode 100644 20220915_2336.html (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/server/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Enumerating objects: 3, done. Counting objects: 100% (3/3), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (2/2), 248 bytes | 248.00 KiB/s, done. Total 2 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/ashishjain1547/repo_for_testing.git b20128a..80b40f5 main -> mainRun Git Push Command on Local Copies Without Doing a Git Pull First.
Local Copy 1
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1$ cd repo_for_testing/ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ echo " " > 20220915_2340.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git commit -m "20220915 Update on local copy 1" [main a01092f] 20220915 Update on local copy 1 1 file changed, 1 insertion(+) create mode 100644 20220915_2340.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': To https://github.com/ashishjain1547/repo_for_testing.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/ashishjain1547/repo_for_testing.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 3, done. remote: Counting objects: 100% (3/3), done. remote: Compressing objects: 100% (1/1), done. remote: Total 2 (delta 1), reused 2 (delta 1), pack-reused 0 Unpacking objects: 100% (2/2), 228 bytes | 228.00 KiB/s, done. From https://github.com/ashishjain1547/repo_for_testing b20128a..80b40f5 main -> origin/main hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 1 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git log commit a01092fe6048d236bb71b1ea95d80e6084a340aa (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:41:11 2022 +0530 20220915 Update on local copy 1 commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git config pull.rebase false (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Merge made by the 'ort' strategy. 20220915_2336.html | 1 + 1 file changed, 1 insertion(+) create mode 100644 20220915_2336.html (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ ls -l total 64 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:31 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:31 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:31 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:31 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:31 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:47 20220915_2336.html -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:40 20220915_2340.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:31 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:31 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:31 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:31 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:31 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:31 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:31 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git log commit a24385b836c5e877571693b5e15a5a44512c1053 (HEAD -> main) Merge: a01092f 80b40f5 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:47:47 2022 +0530 Merge branch 'main' of https://github.com/ashishjain1547/repo_for_testing commit a01092fe6048d236bb71b1ea95d80e6084a340aa Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:41:11 2022 +0530 20220915 Update on local copy 1 commit 80b40f50dcfebbcc39766c30ae5cb5b253f6d0ba (origin/main, origin/HEAD) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:37:45 2022 +0530 20220915 IILocal copy is ahead of server by two commits.
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 2 commits. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Enumerating objects: 6, done. Counting objects: 100% (6/6), done. Delta compression using up to 4 threads Compressing objects: 100% (4/4), done. Writing objects: 100% (4/4), 529 bytes | 529.00 KiB/s, done. Total 4 (delta 2), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (2/2), completed with 1 local object. To https://github.com/ashishjain1547/repo_for_testing.git 80b40f5..a24385b main -> main (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 1/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree cleanLocal Copy 2
$ git config pull.rebase true # rebase
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2$ cd repo_for_testing/ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ ls -l total 56 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:33 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:33 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:33 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:33 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:33 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:33 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:33 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:33 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:33 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ echo "local copy 2" > 20220915_local_copy_2.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git commit -m "local copy 2" [main 824f879] local copy 2 1 file changed, 1 insertion(+) create mode 100644 20220915_local_copy_2.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': To https://github.com/ashishjain1547/repo_for_testing.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/ashishjain1547/repo_for_testing.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 7, done. remote: Counting objects: 100% (7/7), done. remote: Compressing objects: 100% (4/4), done. remote: Total 6 (delta 4), reused 4 (delta 2), pack-reused 0 Unpacking objects: 100% (6/6), 623 bytes | 311.00 KiB/s, done. From https://github.com/ashishjain1547/repo_for_testing b20128a..a24385b main -> origin/main hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 3 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git config pull.rebase true (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Successfully rebased and updated refs/heads/main. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ ls -l total 68 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:33 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:33 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:33 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 16 00:00 20220915_2336.html -rw-rw-r-- 1 ashish ashish 2 Sep 16 00:00 20220915_2340.txt -rw-rw-r-- 1 ashish ashish 13 Sep 16 00:00 20220915_local_copy_2.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:33 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:33 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:33 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:33 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:33 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:33 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:33 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git log commit 858945ca963a48977eea5682e6dc54eb1f87eba1 (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:58:20 2022 +0530 local copy 2 commit a24385b836c5e877571693b5e15a5a44512c1053 (origin/main, origin/HEAD) Merge: a01092f 80b40f5 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:47:47 2022 +0530 Merge branch 'main' of https://github.com/ashishjain1547/repo_for_testing commit a01092fe6048d236bb71b1ea95d80e6084a340aa Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:41:11 2022 +0530 20220915 Update on local copy 1 commit 80b40f50dcfebbcc39766c30ae5cb5b253f6d0ba Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:37:45 2022 +0530 20220915 II commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': Enumerating objects: 4, done. Counting objects: 100% (4/4), done. Delta compression using up to 4 threads Compressing objects: 100% (2/2), done. Writing objects: 100% (3/3), 305 bytes | 305.00 KiB/s, done. Total 3 (delta 1), reused 0 (delta 0), pack-reused 0 remote: Resolving deltas: 100% (1/1), completed with 1 local object. To https://github.com/ashishjain1547/repo_for_testing.git a24385b..858945c main -> main (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 2/repo_for_testing$Local Copy 3
$ git config pull.ff only # fast-forward only
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3$ cd repo_for_testing/ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch is up to date with 'origin/main'. nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ ls -l total 56 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:34 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:34 202110111920.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:34 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:34 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:34 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:34 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:34 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:34 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:34 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ echo "local copy 3" > 20220915_local_copy_3.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git add -A (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git commit -m "#" [main 5c8d1ff] # 1 file changed, 1 insertion(+) create mode 100644 20220915_local_copy_3.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git push Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': To https://github.com/ashishjain1547/repo_for_testing.git ! [rejected] main -> main (fetch first) error: failed to push some refs to 'https://github.com/ashishjain1547/repo_for_testing.git' hint: Updates were rejected because the remote contains work that you do hint: not have locally. This is usually caused by another repository pushing hint: to the same ref. You may want to first integrate the remote changes hint: (e.g., 'git pull ...') before pushing again. hint: See the 'Note about fast-forwards' in 'git push --help' for details. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch is ahead of 'origin/main' by 1 commit. (use "git push" to publish your local commits) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Enumerating objects: 10, done. remote: Counting objects: 100% (10/10), done. remote: Compressing objects: 100% (6/6), done. remote: Total 9 (delta 5), reused 6 (delta 2), pack-reused 0 Unpacking objects: 100% (9/9), 875 bytes | 437.00 KiB/s, done. From https://github.com/ashishjain1547/repo_for_testing b20128a..858945c main -> origin/main hint: You have divergent branches and need to specify how to reconcile them. hint: You can do so by running one of the following commands sometime before hint: your next pull: hint: hint: git config pull.rebase false # merge (the default strategy) hint: git config pull.rebase true # rebase hint: git config pull.ff only # fast-forward only hint: hint: You can replace "git config" with "git config --global" to set a default hint: preference for all repositories. You can also pass --rebase, --no-rebase, hint: or --ff-only on the command line to override the configured default per hint: invocation. fatal: Need to specify how to reconcile divergent branches. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 4 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git config pull.ff only (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ ls -l total 60 -rw-rw-r-- 1 ashish ashish 29 Sep 15 23:34 20210528_test_branch.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141543.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107141608.txt -rw-rw-r-- 1 ashish ashish 16 Sep 15 23:34 202107211228.txt -rw-rw-r-- 1 ashish ashish 12 Sep 15 23:34 202110111920.txt -rw-rw-r-- 1 ashish ashish 13 Sep 16 00:14 20220915_local_copy_3.txt -rw-rw-r-- 1 ashish ashish 2 Sep 15 23:34 20220915.txt -rw-rw-r-- 1 ashish ashish 7 Sep 15 23:34 Archana.txt -rw-rw-r-- 1 ashish ashish 45 Sep 15 23:34 Ashish -rw-rw-r-- 1 ashish ashish 11357 Sep 15 23:34 LICENSE -rw-rw-r-- 1 ashish ashish 10 Sep 15 23:34 newFile.txt -rw-rw-r-- 1 ashish ashish 36 Sep 15 23:34 README.md -rw-rw-r-- 1 ashish ashish 22 Sep 15 23:34 test_file_20210528.txt (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 4 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git log commit 5c8d1ff9d1e3d40daabf2b7cbcdc9f9b4e9003b3 (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Fri Sep 16 00:14:43 2022 +0530 # commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 commit 335cb1656a8b862733936531d0e00da92cea7f8f (origin/test_branch) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Mon Oct 11 19:39:46 2021 +0530 Create Ashish commit 99da43ac015c1ed065796b4681ce2fdfd34d426c Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:37:33 2021 +0530 We will push this code with new file named Archana. commit be275fd83426869e3d8a27f8346ab903d6343faa Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:20:28 2021 +0530 20211011 1920 commit 9f1b42fe6b2cf1fbc3781cdb463b284f871ad291 Merge: d210505 087a5ca Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:41:37 2021 +0530 Merge branch 'test_branch' into main commit 087a5ca85b88f7303d025e8770183a6eabbeca7a Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:29:09 2021 +0530 20210721 1229 commit d2105058469fdb461a61578f8672e769d4426d79 Merge: daa4600 9017804 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Wed Jul 14 16:25:29 2021 +0530 Merge pull request #1 from ashishjain1547/test_branch Test branch commit 901780465a07e7ce78932226db29a0898a07f4a2 Author: unknown <ashishjain1547@gmail.com> (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': remote: Support for password authentication was removed on August 13, 2021. remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed for 'https://github.com/ashishjain1547/repo_for_testing.git/' (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git pull Username for 'https://github.com': ashishjain1547@gmail.com Password for 'https://ashishjain1547@gmail.com@github.com': fatal: Not possible to fast-forward, aborting. (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git status On branch main Your branch and 'origin/main' have diverged, and have 1 and 4 different commits each, respectively. (use "git pull" to merge the remote branch into yours) nothing to commit, working tree clean (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ git log commit 5c8d1ff9d1e3d40daabf2b7cbcdc9f9b4e9003b3 (HEAD -> main) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Fri Sep 16 00:14:43 2022 +0530 # commit b20128a7b6148aa7ed668cfe2531a54418e61097 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Thu Sep 15 23:21:37 2022 +0530 20220915 commit 335cb1656a8b862733936531d0e00da92cea7f8f (origin/test_branch) Author: Ashish Jain <ashishjain1547@gmail.com> Date: Mon Oct 11 19:39:46 2021 +0530 Create Ashish commit 99da43ac015c1ed065796b4681ce2fdfd34d426c Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:37:33 2021 +0530 We will push this code with new file named Archana. commit be275fd83426869e3d8a27f8346ab903d6343faa Author: unknown <ashishjain1547@gmail.com> Date: Mon Oct 11 19:20:28 2021 +0530 20211011 1920 commit 9f1b42fe6b2cf1fbc3781cdb463b284f871ad291 Merge: d210505 087a5ca Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:41:37 2021 +0530 Merge branch 'test_branch' into main commit 087a5ca85b88f7303d025e8770183a6eabbeca7a Author: unknown <ashishjain1547@gmail.com> Date: Wed Jul 21 12:29:09 2021 +0530 20210721 1229 commit d2105058469fdb461a61578f8672e769d4426d79 Merge: daa4600 9017804 Author: Ashish Jain <ashishjain1547@gmail.com> Date: Wed Jul 14 16:25:29 2021 +0530 Merge pull request #1 from ashishjain1547/test_branch Test branch commit 901780465a07e7ce78932226db29a0898a07f4a2 Author: unknown <ashishjain1547@gmail.com> (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$ (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop/git_practical/local 3/repo_for_testing$
Pages
- Index of Lessons in Technology
- Index of Book Summaries
- Index of Book Lists And Downloads
- Index For Job Interviews Preparation
- Index of "Algorithms: Design and Analysis"
- Python Course (Index)
- Data Analytics Course (Index)
- Index of Machine Learning
- Postings Index
- Index of BITS WILP Exam Papers and Content
- Lessons in Investing
- Index of Math Lessons
- Index of Management Lessons
- Book Requests
- Index of English Lessons
- Index of Medicines
- Index of Quizzes (Educational)
Thursday, September 15, 2022
You have divergent branches and need to specify out of three options (merge, rebase, fast-forward) how to reconcile them. What to do?
Wednesday, September 14, 2022
Ten Commands For Day 1 With Ubuntu
1. (base) ashish@ashishdesktop:~$ ls anaconda3 Desktop Documents Downloads Pictures "PlayOnLinux's virtual drives" Public snap Videos 2. (base) ashish@ashishdesktop:~$ cd Desktop (base) ashish@ashishdesktop:~/Desktop$ ls 'The Tsunami (Class 8th).odt' ws (base) ashish@ashishdesktop:~/Desktop$ ls -l total 28 -rw-rw-r-- 1 ashish ashish 24290 Jul 6 21:37 'The Tsunami (Class 8th).odt' drwxrwxr-x 6 ashish ashish 4096 Mar 15 2022 ws (base) ashish@ashishdesktop:~/Desktop$ (base) ashish@ashishdesktop:~/Desktop$ 3. (base) ashish@ashishdesktop:~/Desktop$ mkdir moni (base) ashish@ashishdesktop:~/Desktop$ ls -l total 32 drwxrwxr-x 2 ashish ashish 4096 Sep 14 20:16 moni -rw-rw-r-- 1 ashish ashish 24290 Jul 6 21:37 'The Tsunami (Class 8th).odt' drwxrwxr-x 6 ashish ashish 4096 Mar 15 2022 ws (base) ashish@ashishdesktop:~/Desktop$ (base) ashish@ashishdesktop:~/Desktop$ cd moni (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 0 4. (base) ashish@ashishdesktop:~/Desktop/moni$ touch moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 0 -rw-rw-r-- 1 ashish ashish 0 Sep 14 20:21 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ 5. (base) ashish@ashishdesktop:~/Desktop/moni$ gedit moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 4 -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ 6. (base) ashish@ashishdesktop:~/Desktop/moni$ ls moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ touch dummy.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 4 -rw-rw-r-- 1 ashish ashish 0 Sep 14 21:58 dummy.html -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ gedit dummy.html (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 8 -rw-rw-r-- 1 ashish ashish 6 Sep 14 21:59 dummy.html -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ rm dummy.html (base) ashish@ashishdesktop:~/Desktop/moni$ (base) ashish@ashishdesktop:~/Desktop/moni$ ls -l total 4 -rw-rw-r-- 1 ashish ashish 35 Sep 14 20:27 moni.html 7. (base) ashish@ashishdesktop:~/Desktop/moni$ cat moni.html <pre> my name is moni singh. </pre> 8. (base) ashish@ashishdesktop:~/Desktop/moni$ pwd /home/ashish/Desktop/moni 9. (base) ashish@ashishdesktop:~/Desktop/moni$ echo $USER ashish (base) ashish@ashishdesktop:~/Desktop/moni$ echo $HOME /home/ashish 10. (base) ashish@ashishdesktop:~/Desktop/moni$ uname -a Linux ashishdesktop 5.15.0-41-generic #44-Ubuntu SMP Wed Jun 22 14:20:53 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux (base) ashish@ashishdesktop:~/Desktop/moni$ uname LinuxTags: Technology,Linux,FAQs
Ques 1: What is Terminal? Ans 1: Terminal is a command line interface to the Ubuntu operating system. As of Oct, 2021: Terminal icon is depicted by a 'black background with letters ">_". "Terminal" is an application that is used to run command like: "ls", "cd" and "echo". manju@manju-desktop:~$ ls Desktop Documents Downloads Music Pictures Public Templates Videos manju@manju-desktop:~$ manju@manju-desktop:~$ ls -l total 32 drwxr-xr-x 2 manju manju 4096 Oct 1 23:34 Desktop drwxr-xr-x 2 manju manju 4096 Oct 1 20:56 Documents drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Downloads drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Music drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Pictures drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Public drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Templates drwxr-xr-x 2 manju manju 4096 Apr 7 11:58 Videos manju@manju-desktop:~$ cd Desktop manju@manju-desktop:~/Desktop$ ls -l total 4 -rw-rw-r-- 1 manju manju 537 Oct 1 23:34 'Beginner FAQs for Ubuntu.txt' --- Ques 2: How to browse internet? Answer 2: Use broswers: 1. Mozilla Firefox Browser. 2. Google Chrome. --- Ques 3: How to install Google Chrome. Answer: Use 'Ubuntu Software'. Step 1: Open "Ubuntu Software". Step 2: Press 'Ctrl+F' to launch 'Find and Search'. OR Step 1: Do a Google search in Firefox: "google chrome ubuntu" Step 2: On "Google Chrome Download" page, select "64 bit .deb (For Debian/Ubuntu)" radio button. Step 3: Click on "Accept and Install". ---
Tuesday, September 13, 2022
Sunday, September 11, 2022
Saturday, September 10, 2022
Monday, September 5, 2022
Hatzine 50 (Hydroxyzine)
Tags: Medicine for dogs,Information about Hydroxyzine
Hydroxyzine Uses
Hydroxyzine is used in the treatment of Anxiety and Skin conditions with inflammation & itching.How Hydroxyzine works
Hydroxyzine is an antihistaminic medication. In allergy, it works by blocking the action of a chemical messenger (histamine). This relieves allergy symptoms such as itching, swelling, and rashes. In short-term anxiety, it works by decreasing the activity in brain, thereby helping you feel relaxed/sleepy.Common side effects of Hydroxyzine
Sedation, Nausea, Vomiting, Upset stomach, Constipation
Creating a dummy database and collection in MongoDB Cloud and reading the dummy document using PyMongo
Login to MongoDB Atlas using your Google credentials. And perform the following actions as shown in screenshots below: 1: 2: 3: 4:Tags: Database,CloudNext, we check for "pymongo"
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ python Python 3.9.12 (main, Apr 5 2022, 06:56:58) [GCC 7.5.0] :: Anaconda, Inc. on linux Type "help", "copyright", "credits" or "license" for more information. >>> import pymongo Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'pymongo' >>> exit() ENV.YML FILE: name: mongodb channels: - conda-forge dependencies: - pip - pymongoEnvironment Setup
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda env create -f env.yml Collecting package metadata (repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.12.0 latest version: 4.14.0 Please update conda by running $ conda update -n base -c defaults conda Downloading and Extracting Packages openssl-3.0.5 | 2.8 MB | ### | 100% python-3.10.6 | 29.0 MB | ### | 100% setuptools-65.3.0 | 782 KB | ### | 100% pymongo-4.2.0 | 1.3 MB | ### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done # # To activate this environment, use # # $ conda activate mongodb # # To deactivate an active environment, use # # $ conda deactivate - - - - - - - - - - (base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda activate mongodb (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda install ipykernel -c conda-forge Collecting package metadata (current_repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.12.0 latest version: 4.14.0 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/ashish/anaconda3/envs/mongodb added / updated specs: - ipykernel The following packages will be downloaded: package | build ---------------------------|----------------- executing-1.0.0 | pyhd8ed1ab_0 19 KB conda-forge ipykernel-6.15.2 | pyh210e3f2_0 96 KB conda-forge ipython-8.4.0 | pyh41d4057_1 552 KB conda-forge jupyter_client-7.3.5 | pyhd8ed1ab_0 91 KB conda-forge psutil-5.9.2 | py310h5764c6d_0 350 KB conda-forge stack_data-0.5.0 | pyhd8ed1ab_0 24 KB conda-forge ------------------------------------------------------------ Total: 1.1 MB The following NEW packages will be INSTALLED: asttokens conda-forge/noarch::asttokens-2.0.8-pyhd8ed1ab_0 backcall conda-forge/noarch::backcall-0.2.0-pyh9f0ad1d_0 backports conda-forge/noarch::backports-1.0-py_2 backports.functoo~ conda-forge/noarch::backports.functools_lru_cache-1.6.4-pyhd8ed1ab_0 debugpy conda-forge/linux-64::debugpy-1.6.3-py310hd8f1fbe_0 decorator conda-forge/noarch::decorator-5.1.1-pyhd8ed1ab_0 entrypoints conda-forge/noarch::entrypoints-0.4-pyhd8ed1ab_0 executing conda-forge/noarch::executing-1.0.0-pyhd8ed1ab_0 ipykernel conda-forge/noarch::ipykernel-6.15.2-pyh210e3f2_0 ipython conda-forge/noarch::ipython-8.4.0-pyh41d4057_1 jedi conda-forge/noarch::jedi-0.18.1-pyhd8ed1ab_2 jupyter_client conda-forge/noarch::jupyter_client-7.3.5-pyhd8ed1ab_0 jupyter_core conda-forge/linux-64::jupyter_core-4.11.1-py310hff52083_0 libsodium conda-forge/linux-64::libsodium-1.0.18-h36c2ea0_1 matplotlib-inline conda-forge/noarch::matplotlib-inline-0.1.6-pyhd8ed1ab_0 nest-asyncio conda-forge/noarch::nest-asyncio-1.5.5-pyhd8ed1ab_0 packaging conda-forge/noarch::packaging-21.3-pyhd8ed1ab_0 parso conda-forge/noarch::parso-0.8.3-pyhd8ed1ab_0 pexpect conda-forge/noarch::pexpect-4.8.0-pyh9f0ad1d_2 pickleshare conda-forge/noarch::pickleshare-0.7.5-py_1003 prompt-toolkit conda-forge/noarch::prompt-toolkit-3.0.30-pyha770c72_0 psutil conda-forge/linux-64::psutil-5.9.2-py310h5764c6d_0 ptyprocess conda-forge/noarch::ptyprocess-0.7.0-pyhd3deb0d_0 pure_eval conda-forge/noarch::pure_eval-0.2.2-pyhd8ed1ab_0 pygments conda-forge/noarch::pygments-2.13.0-pyhd8ed1ab_0 pyparsing conda-forge/noarch::pyparsing-3.0.9-pyhd8ed1ab_0 python-dateutil conda-forge/noarch::python-dateutil-2.8.2-pyhd8ed1ab_0 pyzmq conda-forge/linux-64::pyzmq-23.2.1-py310h330234f_0 six conda-forge/noarch::six-1.16.0-pyh6c4a22f_0 stack_data conda-forge/noarch::stack_data-0.5.0-pyhd8ed1ab_0 tornado conda-forge/linux-64::tornado-6.2-py310h5764c6d_0 traitlets conda-forge/noarch::traitlets-5.3.0-pyhd8ed1ab_0 wcwidth conda-forge/noarch::wcwidth-0.2.5-pyh9f0ad1d_2 zeromq conda-forge/linux-64::zeromq-4.3.4-h9c3ff4c_1 Proceed ([y]/n)? y Downloading and Extracting Packages stack_data-0.5.0 | 24 KB | ### | 100% jupyter_client-7.3.5 | 91 KB | ### | 100% executing-1.0.0 | 19 KB | ### | 100% ipython-8.4.0 | 552 KB | ### | 100% ipykernel-6.15.2 | 96 KB | ### | 100% psutil-5.9.2 | 350 KB | ### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done - - - - - - - - - - (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda install jupyterlab -c conda-forge Collecting package metadata (current_repodata.json): done Solving environment: done ==> WARNING: A newer version of conda exists. <== current version: 4.12.0 latest version: 4.14.0 Please update conda by running $ conda update -n base -c defaults conda ## Package Plan ## environment location: /home/ashish/anaconda3/envs/mongodb added / updated specs: - jupyterlab The following packages will be downloaded: package | build ---------------------------|----------------- anyio-3.6.1 | pyhd8ed1ab_1 83 KB conda-forge babel-2.10.3 | pyhd8ed1ab_0 6.7 MB conda-forge cryptography-37.0.1 | py310h9ce1e76_0 1.5 MB json5-0.9.5 | pyh9f0ad1d_0 20 KB conda-forge jsonschema-4.15.0 | pyhd8ed1ab_0 64 KB conda-forge jupyter_server-1.18.1 | pyhd8ed1ab_0 232 KB conda-forge jupyterlab-3.4.5 | pyhd8ed1ab_0 5.8 MB conda-forge jupyterlab_server-2.15.1 | pyhd8ed1ab_0 49 KB conda-forge nbclassic-0.4.3 | pyhd8ed1ab_0 7.5 MB conda-forge notebook-shim-0.1.0 | pyhd8ed1ab_0 15 KB conda-forge pysocks-1.7.1 | pyha2e5f31_6 19 KB conda-forge requests-2.28.1 | pyhd8ed1ab_1 53 KB conda-forge sniffio-1.3.0 | pyhd8ed1ab_0 14 KB conda-forge websocket-client-1.4.1 | pyhd8ed1ab_0 42 KB conda-forge ------------------------------------------------------------ Total: 22.2 MB The following NEW packages will be INSTALLED: anyio conda-forge/noarch::anyio-3.6.1-pyhd8ed1ab_1 argon2-cffi conda-forge/noarch::argon2-cffi-21.3.0-pyhd8ed1ab_0 argon2-cffi-bindi~ conda-forge/linux-64::argon2-cffi-bindings-21.2.0-py310h5764c6d_2 attrs conda-forge/noarch::attrs-22.1.0-pyh71513ae_1 babel conda-forge/noarch::babel-2.10.3-pyhd8ed1ab_0 beautifulsoup4 conda-forge/noarch::beautifulsoup4-4.11.1-pyha770c72_0 bleach conda-forge/noarch::bleach-5.0.1-pyhd8ed1ab_0 brotlipy conda-forge/linux-64::brotlipy-0.7.0-py310h5764c6d_1004 certifi conda-forge/noarch::certifi-2022.6.15-pyhd8ed1ab_1 cffi conda-forge/linux-64::cffi-1.15.1-py310h255011f_0 charset-normalizer conda-forge/noarch::charset-normalizer-2.1.1-pyhd8ed1ab_0 cryptography pkgs/main/linux-64::cryptography-37.0.1-py310h9ce1e76_0 defusedxml conda-forge/noarch::defusedxml-0.7.1-pyhd8ed1ab_0 flit-core conda-forge/noarch::flit-core-3.7.1-pyhd8ed1ab_0 icu conda-forge/linux-64::icu-70.1-h27087fc_0 idna conda-forge/noarch::idna-3.3-pyhd8ed1ab_0 importlib-metadata conda-forge/linux-64::importlib-metadata-4.11.4-py310hff52083_0 importlib_metadata conda-forge/noarch::importlib_metadata-4.11.4-hd8ed1ab_0 importlib_resourc~ conda-forge/noarch::importlib_resources-5.9.0-pyhd8ed1ab_0 ipython_genutils conda-forge/noarch::ipython_genutils-0.2.0-py_1 jinja2 conda-forge/noarch::jinja2-3.1.2-pyhd8ed1ab_1 json5 conda-forge/noarch::json5-0.9.5-pyh9f0ad1d_0 jsonschema conda-forge/noarch::jsonschema-4.15.0-pyhd8ed1ab_0 jupyter_server conda-forge/noarch::jupyter_server-1.18.1-pyhd8ed1ab_0 jupyterlab conda-forge/noarch::jupyterlab-3.4.5-pyhd8ed1ab_0 jupyterlab_pygmen~ conda-forge/noarch::jupyterlab_pygments-0.2.2-pyhd8ed1ab_0 jupyterlab_server conda-forge/noarch::jupyterlab_server-2.15.1-pyhd8ed1ab_0 libiconv conda-forge/linux-64::libiconv-1.16-h516909a_0 libxml2 conda-forge/linux-64::libxml2-2.9.14-h22db469_4 libxslt conda-forge/linux-64::libxslt-1.1.35-h8affb1d_0 lxml conda-forge/linux-64::lxml-4.9.1-py310h5764c6d_0 markupsafe conda-forge/linux-64::markupsafe-2.1.1-py310h5764c6d_1 mistune conda-forge/noarch::mistune-2.0.4-pyhd8ed1ab_0 nbclassic conda-forge/noarch::nbclassic-0.4.3-pyhd8ed1ab_0 nbclient conda-forge/noarch::nbclient-0.6.7-pyhd8ed1ab_0 nbconvert conda-forge/noarch::nbconvert-7.0.0-pyhd8ed1ab_0 nbconvert-core conda-forge/noarch::nbconvert-core-7.0.0-pyhd8ed1ab_0 nbconvert-pandoc conda-forge/noarch::nbconvert-pandoc-7.0.0-pyhd8ed1ab_0 nbformat conda-forge/noarch::nbformat-5.4.0-pyhd8ed1ab_0 notebook conda-forge/noarch::notebook-6.4.12-pyha770c72_0 notebook-shim conda-forge/noarch::notebook-shim-0.1.0-pyhd8ed1ab_0 pandoc conda-forge/linux-64::pandoc-2.19.2-ha770c72_0 pandocfilters conda-forge/noarch::pandocfilters-1.5.0-pyhd8ed1ab_0 pkgutil-resolve-n~ conda-forge/noarch::pkgutil-resolve-name-1.3.10-pyhd8ed1ab_0 prometheus_client conda-forge/noarch::prometheus_client-0.14.1-pyhd8ed1ab_0 pycparser conda-forge/noarch::pycparser-2.21-pyhd8ed1ab_0 pyopenssl conda-forge/noarch::pyopenssl-22.0.0-pyhd8ed1ab_0 pyrsistent conda-forge/linux-64::pyrsistent-0.18.1-py310h5764c6d_1 pysocks conda-forge/noarch::pysocks-1.7.1-pyha2e5f31_6 python-fastjsonsc~ conda-forge/noarch::python-fastjsonschema-2.16.1-pyhd8ed1ab_0 pytz conda-forge/noarch::pytz-2022.2.1-pyhd8ed1ab_0 requests conda-forge/noarch::requests-2.28.1-pyhd8ed1ab_1 send2trash conda-forge/noarch::send2trash-1.8.0-pyhd8ed1ab_0 sniffio conda-forge/noarch::sniffio-1.3.0-pyhd8ed1ab_0 soupsieve conda-forge/noarch::soupsieve-2.3.2.post1-pyhd8ed1ab_0 terminado conda-forge/linux-64::terminado-0.15.0-py310hff52083_0 tinycss2 conda-forge/noarch::tinycss2-1.1.1-pyhd8ed1ab_0 typing_extensions conda-forge/noarch::typing_extensions-4.3.0-pyha770c72_0 urllib3 conda-forge/noarch::urllib3-1.26.11-pyhd8ed1ab_0 webencodings conda-forge/noarch::webencodings-0.5.1-py_1 websocket-client conda-forge/noarch::websocket-client-1.4.1-pyhd8ed1ab_0 zipp conda-forge/noarch::zipp-3.8.1-pyhd8ed1ab_0 Proceed ([y]/n)? y Downloading and Extracting Packages websocket-client-1.4 | 42 KB | ### | 100% nbclassic-0.4.3 | 7.5 MB | ### | 100% anyio-3.6.1 | 83 KB | ### | 100% sniffio-1.3.0 | 14 KB | ### | 100% pysocks-1.7.1 | 19 KB | ### | 100% babel-2.10.3 | 6.7 MB | ### | 100% notebook-shim-0.1.0 | 15 KB | ### | 100% jupyterlab_server-2. | 49 KB | ### | 100% json5-0.9.5 | 20 KB | ### | 100% jupyterlab-3.4.5 | 5.8 MB | ### | 100% jsonschema-4.15.0 | 64 KB | ### | 100% jupyter_server-1.18. | 232 KB | ### | 100% requests-2.28.1 | 53 KB | ### | 100% cryptography-37.0.1 | 1.5 MB | ### | 100% Preparing transaction: done Verifying transaction: done Executing transaction: done (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$Installing kernel for Jupyter Lab
(mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ python -m ipykernel install --user --name mongodb Installed kernelspec mongodb in /home/ashish/.local/share/jupyter/kernels/mongodb (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$Testing Python Environment
import pymongo client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") db = client.test --------------------------------------------------------------------------- ConfigurationError Traceback (most recent call last) Input In [1], in <cell line: 2>() 1 import pymongo ----> 2 client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") 3 db = client.test File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/mongo_client.py:726, in MongoClient.__init__(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs) 722 if timeout is not None: 723 timeout = common.validate_timeout_or_none_or_zero( 724 keyword_opts.cased_key("connecttimeoutms"), timeout 725 ) --> 726 res = uri_parser.parse_uri( 727 entity, 728 port, 729 validate=True, 730 warn=True, 731 normalize=False, 732 connect_timeout=timeout, 733 srv_service_name=srv_service_name, 734 srv_max_hosts=srv_max_hosts, 735 ) 736 seeds.update(res["nodelist"]) 737 username = res["username"] or username File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/uri_parser.py:469, in parse_uri(uri, default_port, validate, warn, normalize, connect_timeout, srv_service_name, srv_max_hosts) 467 if not _HAVE_DNSPYTHON: 468 python_path = sys.executable or "python" --> 469 raise ConfigurationError( 470 'The "dnspython" module must be ' 471 "installed to use mongodb+srv:// URIs. " 472 "To fix this error install pymongo with the srv extra:\n " 473 '%s -m pip install "pymongo[srv]"' % (python_path) 474 ) 475 is_srv = True 476 scheme_free = uri[SRV_SCHEME_LEN:] ConfigurationError: The "dnspython" module must be installed to use mongodb+srv:// URIs. To fix this error install pymongo with the srv extra: /home/ashish/anaconda3/envs/mongodb/bin/python -m pip install "pymongo[srv]"Fix:
(base) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ conda activate mongodb (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ python -m pip install "pymongo[srv]" Requirement already satisfied: pymongo[srv] in /home/ashish/anaconda3/envs/mongodb/lib/python3.10/site-packages (4.2.0) Collecting dnspython<3.0.0,>=1.16.0 Downloading dnspython-2.2.1-py3-none-any.whl (269 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 269.1/269.1 kB 123.6 kB/s eta 0:00:00 Installing collected packages: dnspython Successfully installed dnspython-2.2.1 (mongodb) ashish@ashish-Lenovo-ideapad-130-15IKB:~/Desktop$ISSUE WITH SPECIAL CHARACTERS IN PASSWORD
import pymongo client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") db = client.test --------------------------------------------------------------------------- InvalidURI Traceback (most recent call last) Input In [1], in <cell line: 2>() 1 import pymongo ----> 2 client = pymongo.MongoClient("mongodb+srv://$USERNAME:$PASSWORD@abc.xyz.mongodb.net/?retryWrites=true&w=majority") 3 db = client.test File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/mongo_client.py:726, in MongoClient.__init__(self, host, port, document_class, tz_aware, connect, type_registry, **kwargs) 722 if timeout is not None: 723 timeout = common.validate_timeout_or_none_or_zero( 724 keyword_opts.cased_key("connecttimeoutms"), timeout 725 ) --> 726 res = uri_parser.parse_uri( 727 entity, 728 port, 729 validate=True, 730 warn=True, 731 normalize=False, 732 connect_timeout=timeout, 733 srv_service_name=srv_service_name, 734 srv_max_hosts=srv_max_hosts, 735 ) 736 seeds.update(res["nodelist"]) 737 username = res["username"] or username File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/uri_parser.py:516, in parse_uri(uri, default_port, validate, warn, normalize, connect_timeout, srv_service_name, srv_max_hosts) 514 if "@" in host_part: 515 userinfo, _, hosts = host_part.rpartition("@") --> 516 user, passwd = parse_userinfo(userinfo) 517 else: 518 hosts = host_part File ~/anaconda3/envs/mongodb/lib/python3.10/site-packages/pymongo/uri_parser.py:71, in parse_userinfo(userinfo) 60 """Validates the format of user information in a MongoDB URI. 61 Reserved characters that are gen-delimiters (":", "/", "?", "#", "[", 62 "]", "@") as per RFC 3986 must be escaped. (...) 68 - `userinfo`: A string of the form <username>:<password> 69 """ 70 if "@" in userinfo or userinfo.count(":") > 1 or _unquoted_percent(userinfo): ---> 71 raise InvalidURI( 72 "Username and password must be escaped according to " 73 "RFC 3986, use urllib.parse.quote_plus" 74 ) 76 user, _, passwd = userinfo.partition(":") 77 # No password is expected with GSSAPI authentication. InvalidURI: Username and password must be escaped according to RFC 3986, use urllib.parse.quote_plusAll Issues Resolved. See Successful Code Run Below:
import pymongo import urllib uri = "mongodb+srv://$USERNAME:" + urllib.parse.quote_plus("$PASSWORD") + "@abc.xyz.mongodb.net/?retryWrites=true&w=majority" client = pymongo.MongoClient(uri) print(client) MongoClient(host=['ac-af4wahu-shard-00-02.xyz.mongodb.net:27017', 'ac-af4wahu-shard-00-01.xyz.mongodb.net:27017', 'ac-af4wahu-shard-00-00.xyz.mongodb.net:27017'], document_class=dict, tz_aware=False, connect=True, retrywrites=True, w='majority', authsource='admin', replicaset='atlas-3xaqbc-shard-0', tls=True) db = client['db1'] collection = db['ccn1'] print(collection.count_documents({})) # Output: 1 print(collection.find({})) <pymongo.cursor.Cursor at 0x7fd632c38850> import pprint for doc in collection.find(): pprint.pprint(doc) {'_id': ObjectId('6315c3a74afb509774a88467'), 'address': 'Delhi', 'name': 'Ashish Jain'}
Tuesday, August 30, 2022
Prediction of Infy Stock Market Price using LSTM based model
Download Code and Data
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from tensorflow import keras
#import the Keras layers
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding,Dense, Dropout, LSTM, Dropout,Activation
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
from sklearn.utils import shuffle
# Loading data
data = pd.read_csv('files_input/infy/infy_2000 to 2008.csv')
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2496 entries, 0 to 2495
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Symbol 2496 non-null object
1 Series 2496 non-null object
2 Date 2496 non-null object
3 Prev Close 2496 non-null float64
4 Open Price 2496 non-null float64
5 High Price 2496 non-null float64
6 Low Price 2496 non-null float64
7 Last Price 2496 non-null float64
8 Close Price 2496 non-null float64
9 Average Price 2496 non-null float64
10 Total Traded Quantity 2496 non-null int64
11 Turnover 2496 non-null float64
12 No. of Trades 2496 non-null object
13 Deliverable Qty 2496 non-null object
14 % Dly Qt to Traded Qty 2496 non-null object
dtypes: float64(8), int64(1), object(6)
memory usage: 292.6+ KB
data.head()
# Selecting only Date and Average Price columns
data = data[['Open Price', 'Average Price']]
# Scaling the values in the range of 0 to 1
scaler = MinMaxScaler(feature_range = (0, 1))
scaled_price = scaler.fit_transform(data.loc[:, 'Average Price'].values.reshape(-1, 1))
# Splitting dataset in the ratio of 75:25 for training and test
train_size = int(data.shape[0] * 0.75)
train, test = scaled_price[0:train_size, :], scaled_price[train_size:data.shape[0], :]
print("Number of entries (training set, test set): " + str((len(train), len(test))))
Number of entries (training set, test set): (1872, 624)
def create_dataset(scaled_price, window_size=1):
data_X, data_Y = [], []
for i in range(len(scaled_price) - window_size - 1):
a = scaled_price[i:(i + window_size), 0]
data_X.append(a)
data_Y.append(scaled_price[i + window_size, 0])
return(np.array(data_X), np.array(data_Y))
# Create test and training sets for one-step-ahead regression.
window_size = 3
train_X, train_Y = create_dataset(train, window_size)
test_X, test_Y = create_dataset(test, window_size)
print("Original training data shape:")
print(train_X.shape)
# Reshape the input data into appropriate form for Keras.
train_X = np.reshape(train_X, (train_X.shape[0], 1, train_X.shape[1]))
test_X = np.reshape(test_X, (test_X.shape[0], 1, test_X.shape[1]))
print("New training data shape:")
print(train_X.shape)
Original training data shape:
(1868, 3)
New training data shape:
(1868, 1, 3)
The LSTM architecture here consists of:
One input layer.
One LSTM layer of 4 blocks.
One Dense layer to produce a single output.
MSE as loss function.
# Designing the LSTM model
model = Sequential()
model.add(LSTM(4, input_shape = (1, window_size)))
model.add(Dense(1))
2022-08-30 18:27:28.769044: I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 AVX AVX2 FMA
To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.
# Compiling the model
model.compile(loss = "mean_squared_error", optimizer = "adam")
# Training the model
model.fit(train_X, train_Y, epochs=10, batch_size=1)
Epoch 1/10
1868/1868 [==============================] - 8s 3ms/step - loss: 0.0053
Epoch 2/10
1868/1868 [==============================] - 5s 3ms/step - loss: 4.7545e-04
Epoch 3/10
1868/1868 [==============================] - 5s 3ms/step - loss: 4.2540e-04
Epoch 4/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.7605e-04
Epoch 5/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.4645e-04
Epoch 6/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.4557e-04
Epoch 7/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.2880e-04
Epoch 8/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.2757e-04
Epoch 9/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.0206e-04
Epoch 10/10
1868/1868 [==============================] - 5s 3ms/step - loss: 3.0305e-04
<keras.callbacks.History at 0x7fc9645e75b0>
def predict_and_score(model, X, Y):
# Make predictions on the original scale of the data.
predicted = scaler.inverse_transform(model.predict(X))
# Prepare Y data to also be on the original scale for interpretability.
orig_data = scaler.inverse_transform([Y])
# Calculate RMSE.
score = np.sqrt(mean_squared_error(orig_data[0], predicted[:, 0]))
return(score, predicted)
rmse_train, train_predict = predict_and_score(model, train_X, train_Y)
rmse_test, test_predict = predict_and_score(model, test_X, test_Y)
print("Training data score: %.2f RMSE" % rmse_train)
print("Test data score: %.2f RMSE" % rmse_test)
59/59 [==============================] - 1s 2ms/step
20/20 [==============================] - 0s 2ms/step
Training data score: 248.61 RMSE
Test data score: 63.50 RMSE
# Create the plot for predicted and the training data.
plt.figure(figsize = (15, 5))
plt.plot(scaler.inverse_transform(scaled_price), label = "True value")
plt.plot(train_predict, label = "Training set prediction")
plt.xlabel("Days")
plt.ylabel("Average Price")
plt.title("Comparison true vs. predicted training set")
plt.legend()
plt.show()
test_predict_padded = np.concatenate(([[1900], [1900], [1900], [1900]], test_predict))
print("test_predict_padded.shape: ", test_predict_padded.shape)
test_predict_padded.shape: (624, 1)
test_orig = data[['Average Price']].iloc[train_size:data.shape[0], :]
test_orig.reset_index(inplace = True, drop=True)
print("test_orig.shape: ", test_orig.shape)
print("test_predict.shape: ", test_predict.shape)
test_orig.shape: (624, 1)
test_predict.shape: (620, 1)
# Create the plot for predicted and the training data.
plt.figure(figsize = (15, 5))
plt.plot(test_predict_padded[0:200], label = "Test set prediction")
plt.plot(test_orig[0:200], label = "Test set actual data points")
plt.xlabel("Days")
plt.ylabel("Average Price")
plt.title("Comparison true vs. predicted on test set")
plt.legend()
plt.show()
Tags: Deep Learning
Sunday, August 28, 2022
Prediction of Infy stock market price using Recurrent Neural Network
Download Code and Data
This code demonstrates the prediction of stock market price using Recurrent Neural Networks.
Dataset: Infosys stock market price from 2000 to 2008 is used to train the RNN model.
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
from tensorflow import keras
#import the Keras layers
from tensorflow.keras.models import Sequential
from tensorflow.keras.layers import Embedding,Dense, Dropout, LSTM, Dropout,Activation
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
from sklearn.utils import shuffle
# Loading data
data = pd.read_csv('files_input/infy/infy_2000 to 2008.csv')
data.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 2496 entries, 0 to 2495
Data columns (total 15 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 Symbol 2496 non-null object
1 Series 2496 non-null object
2 Date 2496 non-null object
3 Prev Close 2496 non-null float64
4 Open Price 2496 non-null float64
5 High Price 2496 non-null float64
6 Low Price 2496 non-null float64
7 Last Price 2496 non-null float64
8 Close Price 2496 non-null float64
9 Average Price 2496 non-null float64
10 Total Traded Quantity 2496 non-null int64
11 Turnover 2496 non-null float64
12 No. of Trades 2496 non-null object
13 Deliverable Qty 2496 non-null object
14 % Dly Qt to Traded Qty 2496 non-null object
dtypes: float64(8), int64(1), object(6)
memory usage: 292.6+ KB
data.head()
# Selecting only Date and Average Price columns
data = data[['Open Price', 'Average Price']]
# Scaling the values in the range of 0 to 1
scaler = MinMaxScaler(feature_range = (0, 1))
scaled_price = scaler.fit_transform(data.loc[:, 'Average Price'].values.reshape(-1, 1))
# Splitting dataset in the ratio of 75:25 for training and test
train_size = int(data.shape[0] * 0.75)
train, test = scaled_price[0:train_size, :], scaled_price[train_size:data.shape[0], :]
print("Number of entries (training set, test set): " + str((len(train), len(test))))
Number of entries (training set, test set): (1872, 624)
def create_dataset(scaled_price, window_size=1):
data_X, data_Y = [], []
for i in range(len(scaled_price) - window_size - 1):
a = scaled_price[i:(i + window_size), 0]
data_X.append(a)
data_Y.append(scaled_price[i + window_size, 0])
return(np.array(data_X), np.array(data_Y))
# Create test and training sets for one-step-ahead regression.
window_size = 3
train_X, train_Y = create_dataset(train, window_size)
test_X, test_Y = create_dataset(test, window_size)
print("Original training data shape:")
print(train_X.shape)
# Reshape the input data into appropriate form for Keras.
train_X = np.reshape(train_X, (train_X.shape[0], 1, train_X.shape[1]))
test_X = np.reshape(test_X, (test_X.shape[0], 1, test_X.shape[1]))
print("New training data shape:")
print(train_X.shape)
Original training data shape:
(1868, 3)
New training data shape:
(1868, 1, 3)
Keras simple RNN is layer is built as the first layer, then 2 dense layers is added.
import tensorflow as tf
model = tf.keras.Sequential([
tf.keras.layers.SimpleRNN(32),
tf.keras.layers.Dense(10, activation='relu'),
tf.keras.layers.Dense(1, activation='sigmoid')
])
# SimpleRNN model can also be created using Keras simpleRNN class
# Learners can uncomment the below code to create the simpleRNN using Keras
# from tensorflow.keras.models import Model
# from tensorflow.keras.layers import SimpleRNN
# model = Sequential()
# model.add(SimpleRNN(units = 32, return_sequences=False, unroll=True, input_shape=(6, 2)))
# Compiling the model
model.compile(loss = "mean_squared_error", optimizer = "adam")
# Training the model
model.fit(train_X, train_Y, epochs=10, batch_size=1)
Epoch 1/10
1868/1868 [==============================] - 7s 3ms/step - loss: 0.0077
Epoch 2/10
1868/1868 [==============================] - 4s 2ms/step - loss: 6.4751e-04
Epoch 3/10
1868/1868 [==============================] - 4s 2ms/step - loss: 4.6002e-04
Epoch 4/10
1868/1868 [==============================] - 5s 2ms/step - loss: 4.2450e-04
Epoch 5/10
1868/1868 [==============================] - 5s 2ms/step - loss: 3.8224e-04
Epoch 6/10
1868/1868 [==============================] - 4s 2ms/step - loss: 3.8648e-04
Epoch 7/10
1868/1868 [==============================] - 4s 2ms/step - loss: 3.6662e-04
Epoch 8/10
1868/1868 [==============================] - 4s 2ms/step - loss: 3.8370e-04
Epoch 9/10
1868/1868 [==============================] - 4s 2ms/step - loss: 3.3650e-04
Epoch 10/10
1868/1868 [==============================] - 4s 2ms/step - loss: 3.4760e-04
<keras.callbacks.History at 0x7feaf84d0bb0>
def predict_and_score(model, X, Y):
# Make predictions on the original scale of the data.
predicted = scaler.inverse_transform(model.predict(X))
# Prepare Y data to also be on the original scale for interpretability.
orig_data = scaler.inverse_transform([Y])
# Calculate RMSE.
score = np.sqrt(mean_squared_error(orig_data[0], predicted[:, 0]))
return(score, predicted)
rmse_train, train_predict = predict_and_score(model, train_X, train_Y)
rmse_test, test_predict = predict_and_score(model, test_X, test_Y)
print("Training data score: %.2f RMSE" % rmse_train)
print("Test data score: %.2f RMSE" % rmse_test)
59/59 [==============================] - 1s 2ms/step
20/20 [==============================] - 0s 2ms/step
Training data score: 273.58 RMSE
Test data score: 277.63 RMSE
# Create the plot for predicted and the training data.
plt.figure(figsize = (15, 5))
plt.plot(scaler.inverse_transform(scaled_price), label = "True value")
plt.plot(train_predict, label = "Training set prediction")
plt.xlabel("Days")
plt.ylabel("Average Price")
plt.title("Comparison true vs. predicted training set")
plt.legend()
plt.show()
test_predict.shape
(620, 1)
test_orig = data[['Average Price']].iloc[train_size:data.shape[0], :]
test_orig.reset_index(inplace = True, drop=True)
print(test_orig.shape)
(624, 1)
test_orig.head()
# Create the plot for predicted and the training data.
plt.figure(figsize = (15, 5))
plt.plot(test_predict, label = "Test set prediction")
plt.plot(test_orig, label = "Test set actual data points")
plt.xlabel("Days")
plt.ylabel("Average Price")
plt.title("Comparison true vs. predicted on test set")
plt.legend()
plt.show()
Tags: Deep Learning,Investment,
Thursday, August 25, 2022
A Dynamic Strategy Coach for Effective Negotiation (a Natural Language Processing application) 2019-Sep-30
Download Research Paper
Tags: Negotiation,Natural Language Processing,Abstract
Negotiation is a complex activity involving strategic reasoning, persuasion, and psychology. An average person is often far from an expert in negotiation. Our goal is to assist humans to become better negotiators through a machine-in-the-loop approach that combines machine’s advantage at data-driven decisionmaking and human’s language generation ability. We consider a bargaining scenario where a seller and a buyer negotiate the price of an item for sale through a text-based dialog. Our negotiation coach monitors messages between them and recommends tactics in real time to the seller to get a better deal (e.g., “reject the proposal and propose a price”, “talk about your personal experience with the product”). The best strategy and tactics largely depend on the context (e.g., the current price, the buyer’s attitude). Therefore, we first identify a set of negotiation tactics, then learn to predict the best strategy and tactics in a given dialog context from a set of human–human bargaining dialogs. Evaluation on human–human dialogs shows that our coach increases the profits of the seller by almost 60%.1: Introduction
Negotiation is a social activity that requires both strategic reasoning and communication skills (Thompson, 2001; Thompson et al., 2010). Even humans require years of training to become a good negotiator. Past efforts on building automated negotiation agents (Traum et al., 2008; Cuay´ahuitl et al., 2015; Keizer et al., 2017; Cao et al., 2018; Petukhova et al., 2017; Papangelis and Georgila, 2015) has primarily focused on the strategic aspect, where negotiation is formulated as a sequential decision-making process with a discrete action space, leaving aside the rhetorical aspect. Recently, there has been a growing interest in strategic goal-oriented dialog (He et al., 2017; Lewis et al., 2017; Yarats and Lewis, 2018; He et al., 2018) that aims to handle both reasoning and text generation. While the models are good at learning strategies from human–human dialog and selfplay, there is still a huge gap between machine generated text and human utterances in terms of diversity and coherence (Li et al., 2016a,b). In this paper, we introduce a machine-in-theloop approach (cf. Clark et al., 2018) that combines the language skills of humans and the decision-making skills of machines in negotiation dialogs. Our negotiation coach assists users in real time to make good deals in a bargaining scenario between a buyer and a seller. We focus on helping the seller to achieve a better deal by providing suggestions on what to say and how to say it when responding to the buyer at each turn. As shown in Figure 1, during the (human–human) conversation, our coach analyzes the current dialog history, and makes both high-level strategic suggestions (e.g., hpropose a pricei) and low-level rhetoric suggestions (e.g., huse hedge wordsi). The seller then relies on these suggestions to formulate their response. While there exists a huge body of literature on negotiation in behavioral economics (Pruitt, 1981; Bazerman et al., 2000; Fisher and Ury, 1981; Lax and Sebenius, 2006; Thompson et al., 2010), these studies typically provide case studies and generic principles such as “focus on mutual gain”. Instead of using these abstract, static principles, we draw insights from prior negotiation literature and define actionable strategies and tactics conditioned on the negotiation scenario and the dialog context. We take a data-driven approach (§2) using human – human negotiation dialogs collected in a simulated online bargaining setting (He et al., 2018). Figure 1: Our negotiation coach monitors the conversation between the seller and the buyer, and provides suggestions of negotiation tactics to the seller in each turn dynamically, depending on the negotiation scenario, the dialog context, and examples of previous similar dialogs. First, we build detectors to extract negotiation tactics grounded in each turn, such as product embellishment (“The TV works like a champ!”) and side offers (“I can deliver it to you.”) (§3.1). These turn-level tactics allow us to dynamically predict the tactics used in a next utterance given the dialog context. To quantify the effectiveness of each tactic, we further build an outcome predictor to predict the final deal given past tactics sequence extracted from the dialog history (§5). At test time, given the dialog history in each turn, our coach (1) predicts possible tactics in the next turn (§4); (2) uses the outcome predictor to select tactics that will lead to a good deal; (3) retrieves (lexicalized) examples exhibiting the selected tactics and displays them to the seller (§6). To evaluate the effectiveness of our negotiation coach, we integrate it into He et al.’s (2018) negotiation dialog chat interface and deploy the system on Amazon Mechanical Turk (AMT) (§7). We compare with two baselines: the default setting (no coaching) and the static coaching setting where a tutorial on effective negotiation strategies and tactics is given to the user upfront. The results show that our dynamic negotiation coach helps sellers increase profits by 59% and achieves the highest agreement rate.2: Problem Statement
We follow the CraigslistBargain setting of He et al. (2018), where a buyer and a seller negotiate the price of an item for sale. The negotiation scenario is based on listings scraped from craigslist.com, including product description, product photos (if available), and the listing price. In addition, the buyer is given a private target price that they aim to achieve. Two AMT workers are randomly paired to play the role of the seller and the buyer. They negotiate through the chat interface shown in Figure 2 in a strict turn-taking manner. They are instructed to negotiate hard for a favorable price. Once an agreement is reached, either party can submit the price and the other chooses to accept or reject the deal; the task is then completed. Our goal is to help the seller achieve a better deal (i.e. higher final price) by providing suggestions on how to respond to the buyer during the conversation. At each seller’s turn, the coach takes the negotiation scenario and the current dialog history as input and predicts the best tactics to use in the next turn to achieve a higher final price. The seller has the freedom to choose whether to use the recommended tactics.3: Approach
We define a set of diverse tactics S from past study on negotiation in behavioral economics, including both high-level dialog acts (e.g., (propose a price), (describe the product) and low-level lexical features (e.g. (use hedge words). Given the negotiation scenario and the dialog history, the coach takes the following steps (Figure 3) to generate suggestions: 1. The tactics detectors map each turn to a set of tactics in S. 2. The tactics predictor predicts the set of possible tactics in the next turn given the dialog history. For example, if the buyer has proposed a price, possible tactics include proposing a counter price, agreeing with the price etc. 3. The tactics selector takes the candidate tactics from the tactics predictor and selects those that lead to a better final deal. 4. The tactics realizer converts the selected tactics to instructions and examples in natural language, which are then presented to the seller. We detail each step in the following sections. 3.1 Tactics Detectors We focus on two broad categories of strategies in behavioral research: (i) integrative, or win–win, negotiation, in which negotiators seek to build relationships and reach an agreement benefiting both parties; and (ii) distributive, or win–lose, negotiation, in which negotiators adversarially promote their own interests, exert power, bluff, and demand (Walton and McKersie, 1965). In practice, effective negotiation often involves both types of strategies (Fisher and Ury, 1981; Lax and Sebenius, 2006; Pruitt, 1981; K. et al., 2000, inter alia). Prior work typically focuses on conceptual tactics (e.g., emphasize mutual interest), rather than actionable tactics in a specific negotiation scenario (e.g., politely decline to lower the price, but offer free delivery). Therefore, we develop datadriven ways to operationalize and quantify these abstract principles. In Table 1, we list our actionable tactics motivated by various negotiation principles. To detect these tactics from turns, we use a mix of learned classifiers for turn-level tactics (e.g., propose prices) and regular expression rules for lexical tactics (e.g., use polite words). To create the training set for learning tactic predictors, we randomly selected 200 dialogs and annotated them with tactics. The detectors use the following features: (1) the number of words overlapping with the product description; (2) the METEOR score (Denkowski and Lavie, 2014) of the turn given the product description as reference; (3) the cosine distance between the turn embedding and the product description embedding. For “Address buyer’s concerns”, we additionally include lexical features indicating a question (e.g.,“why”, “how”, “does”) from the immediate previous buyer’s turns. Table 2 summarizes the number pf training examples and prediction accuracies for each learned classifier. For lexical tactics, we have the following rules: • (Do not propose first) Waiting for the buyer’s proposal allows the seller to better estimate the buyer’s target. The detector simply keeps track of who proposes a price first by detecting (propose a price). • (Negotiate side offers) The seller sometimes negotiates side offers, e.g., offering a free gift card or free delivery. To detect this strategy, we match the turn against a set of phrases, e.g., “throw in”, “throwing in”, “deliver”, “delivery”, “pick up”, “pick it up”, “in cash”. • (Use factive verbs) defined in (Hooper, 1975) (e.g. know); • (Use hedge words) defined in (Hyland, 2005) (e.g. could, would); • (Use certainty words) defined in the LIWC dictionary (Tausczik and Pennebaker, 2010). • (Communicate politely) We include several politeness-related negotiation tactics that were identified by Danescu- Table 1: Actionable tactics designed based on negotiation principles. Some of them are detected by learning classifiers on annotated data, and the rest are detected using pattern matching. Niculescu-Mizil et al. (2013) as most informative features. They include: gratitude, greetings, apology, “please” in the beginning of a turn, “please” later on. Keywords matching is used to detect these tactics. • (Build rapport) Deepening self-disclosure, e.g., “My kid really liked this bike, but he outgrew it”, is one strategy for building rapport. We implemented three tactics detectors to identify selfdisclosure. First, we count first-person pronouns (Derlaga and Berg, 1987; Joinson, 2001). Second, we count mentions of family members and friends, respectively (Wang et al., 2016). It is done by matching lexicons from family and friend categories in LIWC. • (Talk informally) It is detected by matching the keywords in the informal language category in LIWC. • (Show dominance) To detect stubbornness (Tan et al., 2016), we measure the average dominance score of all the words from the Warriner et al.’s (2013)’s dominance ratings of 14,000 words. • (Express negative sentiment) We measure both positive and negative sentiment by counting words from positive and negative categories in LIWC.8: Conclusion
This paper presents a dynamic negotiation coach that can make measurably good recommendations to sellers that can increase their profits. It benefits from grounding in strategies and tactics within the negotiation literature and uses natural language processing and machine learning techniques to identify and score the tactics’ likelihood of being successful. We have tested this coach on human–human negotiations and shown that our techniques can substantially increase the profit of negotiators who follow our coach’s recommendations. A key contribution of this study is a new task and a framework of an automated coach-in-theloop that provides on-the-fly autocomplete suggestions to the negotiating parties. This framework can seamlessly be integrated in goal-oriented negotiation dialog systems (Lewis et al., 2017; He et al., 2018), and it also has stand-alone educational and commercial values. For example, our coach can provide language and strategy guidance and help improve negotiation skills of non-expert negotiators. In commercial settings, it has a clear use case of assisting humans in sales and in customer service. An additional important contribution lies in aggregating negotiation strategies from economics and behavioral research, and proposing novel ways to operationalize the strategies using linguistic knowledge and resources.9: Appendix
Subscribe to:
Comments (Atom)


























